[fpc-pascal] fpc trunk issue with StreamIO or TMemoryStream

Luca Olivetti luca at ventoso.org
Mon Oct 7 13:41:44 CEST 2019


I'm facing a strange issue, I don't know if it's StreamIO or 
TMemoryStream. The following program, compiled with fpc

Free Pascal Compiler version 3.2.0-beta [2019/04/26] for i386

(I checked trunk and I don't see changes in streams or streamio)

prints 3 lines but they are empty!

---
---
---

If I remove the "stream.position:=0", or I use $H- (or line:shortstring) 
or I avoid the RStream procedure (i.e I put what it does in the main 
program) or I use fpc 3.0.4 it correctly prints

--- a
--- b
--- c

Does it ring any bell?

The stream.position:=0 is really strange, since it just calls seeks 
which in turn only sets FPosition to 0 (and it was already 0!).

In my project I'm actually using a TMemoryStream, but it has the same issue.

Here's the test program

program Project1;
{$mode objfpc}
{$H+}

uses Classes, SysUtils, StreamIO;


procedure RStream(s:TStream);
var f:textfile;
     line:string;
begin
   AssignStream(f,s);
   Reset(f);
   while not eof(f) do
   begin
     readln(f,line);
     writeln('--- ',line);
   end;
   Close(f);
end;

var
   stream: TStringStream;
begin
   stream:=TStringStream.Create('a'#13#10'b'#13#10'c'#13#10);
   stream.position:=0;
   RStream(stream);
   stream.free;
   readln;
end.








More information about the fpc-pascal mailing list