darckness000 wrote:
> I'm trying to read line-feed (ASCII #10) terminated lines from a file 
> (think UNIX file), not the usual CRLF (ASCII #13 #10) terminated 
> lines.
> 
> What I'm doing at the moment is to `Read' 1 char at a time into a var 
> until I hit an LF + then display the string to the user. While this 
> works, it is sloooowwwwwwwwww when seeking to the last line in a 
> large file.

If you want the last line, then maybe you could read backward from the 
end of the file.

> I've tried using `Read' with zero based character arrays - + while 
> this is much faster, read fills the array completely (ie: if the 
> array is [0..999], Read will read 1000 chars from the file) instead 
> of stopping at the LF in the file. As each line in the file is 
> variable in length, I am unable to allocate a static array. Dynamic 
> arrays don't work with `Read', but as I don't the length of each 
> string in the file this doesn't really matter.

You know, that's exactly what ReadLn does. But when it reaches the end 
of a line, it keeps the remainder of the buffer around to use for the 
next line.

> When comparing speed against what I'm currently doing + using ReadLn 
> (ReadLn doesn't read the LF, I was just testing speed), ReadLn is so 
> much quicker it's unbelievable.

Based on my reading of the Delphi 2005 code, it's the line feed that 
makes ReadLn stop reading. Merely a carriage return is _not_ sufficient 
for ending a line. They do not mark the end of a line, and they are not 
copied into the result buffer. What version are you using?

> My question is, does anyone know of a way to read LF terminated lines 
> from a file with speed comparable to ReadLn?

TStrings.LoadFromFile handles all sorts of line-end styles. If you can 
afford to load the entire file into memory.

-- 
Rob

Reply via email to