2010. január 6., szerda

How to write a number (integer, float etc.) to a stream


Problem/Question/Abstract:

How can I write a number (integer, float, etc.) to a stream? I am trying to save the contents of a TList to a TFileStream. First I have to save the count of the number of items in the list and save the count.

Answer:

var
  S: TMemoryStream;
  I: LongInt;
begin
  S := TMemoryStream.Create;
  try
    I := 1234;
    S.Write(I, SizeOf(I));
  finally
    S.Free;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése