Hi,
Probier mal diese Funktion:
Delphi-Quellcode:
function TextLineCount_BufferedStream(const Filename: TFileName): Integer;
const
MAX_BUFFER = 1024 *1024;
var
oStream: TFileStream;
sBuffer: string;
iBufferSize: Integer;
iSeek: Integer;
bCarry: Boolean;
begin
Result := 0;
bCarry := False;
oStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
SetLength(sBuffer, MAX_BUFFER);
repeat
iBufferSize := oStream.Read(sBuffer[1], MAX_BUFFER);
if iBufferSize <= 0 then
break;
{Skip LFs that follow a CR - even if it falls in seperate buffers}
iSeek := 1;
if bCarry and (sBuffer[1] = #10) then
Inc(iSeek);
while iSeek <= iBufferSize do
begin
case sBuffer[iSeek] of
#10:
Inc(Result);
#13:
if iSeek = iBufferSize then
Inc(Result)
else
if sBuffer[iSeek + 1] <> #10 then
Inc(Result)
else
begin
Inc(Result);
Inc(iSeek);
end;
end;
Inc(iSeek);
end;
{Set carry flag for next pass}
bCarry := (sBuffer[iBufferSize] = #13);
until
iBufferSize < MAX_BUFFER;
finally
FreeAndNil(oStream);
end;
end;