On Wed, 7 Jun 2006, Alexandre Leclerc wrote:

2006/6/7, Michael Van Canneyt <[EMAIL PROTECTED]>:


On Wed, 7 Jun 2006, Alexandre Leclerc wrote:

> Well, I tought to improve the function by:
>
> while not WeHaveGotALine
> ReadBufferChunk
> ParseForEol
> - ReadMoreBufferIfRequired
> - SetStreamPositionWhereWeFoundEolToContinueThereLater

You can't do that, because not all streams support positioning
(en-/decoding streams, compression streams, pipes)

> So would that be usefull? Because any-way I must do it; loading a full
> stream inmemory in not memory efficient, and loading it in a
> TStringList has the same issue.

When loading in a stringlist you know that you must copy the whole
stream at once. With readln this is not possible: you don't know how
much you need in advance.

It's simply not possible at the TStream level.

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.

Michael.

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to