Christian Seehase stellt
hier eine Möglichkeit vor, schnell die Zeilen einer Textdatei zu zählen:
Delphi-Quellcode:
function csCountLines(const AsFilepath : string) : Integer;
const
BUFSIZE = 65536;
var
fs : TFileStream;
sBuf : array [1..BUFSIZE] of char;
iLines : Integer;
iRead : integer;
i : Integer;
begin
fs := TFileStream.Create(AsFilepath,fmOpenRead);
try
iLines := 0;
iRead := fs.Read(sBuf,BUFSIZE);
while iRead = BUFSIZE do begin
for i := 1 to iRead do begin
Inc(iLines,Ord(sBuf[i]=#10));
end;
iRead := fs.Read(sBuf,BUFSIZE);
end;
for i := 1 to iRead do begin
Inc(iLines,Ord(sBuf[i]=#10));
end;
if (iRead > 0) and (sBuf[iRead] <> #10) then inc(iLines);
finally
fs.Free;
end;
Result := iLines;
end;