On Wed, 7 Jun 2006, Alexandre Leclerc wrote:
2006/6/7, Michael Van Canneyt <[EMAIL PROTECTED]>:
> So readln / writeln is not possible with streams. This is a problem.
> I'm actually loading a file, but I wanted to use streams internally to
> increase flexibility; I might exchange data with memory streams on the
> long run.
You can use the file-to-stream bridge. Unit streamio:
Procedure AssignStream(var F: Textfile; Stream: TStream);
Function GetStream(var F: TTextRec) : TStream;
usage:
Var
M : TStream;
F : Text;
l : String;
begin
M:=TMyStream.Create;
Try
AssignStream(F,M);
Reset(F);
// Read your stuff here
ReadLn(L,F);
Close(F);
Finally
FreeAndNil(M);
end;
end;
This will always work.
It took me couple minutes to understand. This is very interesting. It
still double the data in memory, like a TStringList;
No. There is just a simple 256 byte buffer, that's it.
but I'm glad to
see that. I see that low memory usage equals direct text access with
readln/writeln. But I've no time to mess arround with that now.
It is in an include file (.inc). how can I use such a file without {$i
} ? Like in a use clause?
it's not an include file. streamio.pp is in fcl/inc
and is compiled and installed by default.
Michael.
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives