[fpc-devel] Read from memory stream with position before start of file

Paul Ishenin webpirat at mail.ru
Thu Jan 1 17:48:25 CET 2009

Michael Van Canneyt wrote:
>> If you do an exception or silent change of position it can cause
>> incompatibilities. Maybe read operation must be fixed to ignore positions out
>> of the range 0..Size -1?
> What does Delphi do in such a case ?
Tested so:

procedure TForm1.Button1Click(Sender: TObject);
  S: TMemoryStream;
  B: Byte;
  Count: Integer;
  S := TMemoryStream.Create;
  B := 1;
  S.Write(B, SizeOf(B));
  S.Position := -1;
  Count := S.Read(B, SizeOf(B));

Count = 0. IOW, delphi does not read if position < 0

Best regards,
Paul Ishenin.

More information about the fpc-devel mailing list