Hmm det lader til at experts-exchange låser svarene efter et antal visninger, så jeg paster lige hans svar.
My suggestion is this:
(1) Open the log file as a memory mapped file like this (the code is written from my head and NOT tested):
var file_, map : dword;
view : pchar;
sizeL, sizeH : dword;
size64 : int64;
begin
file_ := CreateFile('c:\your.log', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if file_ <> INVALID_HANDLE_VALUE then begin
sizeL := GetFileSize(file_, @sizeH);
size64 := int64(sizeH) shl 32 + sizeL;
map := CreateFileMapping(file_, nil, PAGE_READWRITE, 0, 0, nil);
if map <> 0 then begin
view := MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
if view <> nil then begin
[...] // here you have the file in memory at pointer "view" with the length "size64"
UnmapViewOfFile(view);
end;
CloseHandle(map);
end;
CloseHandle(file_);
end;
end;
Please note that the file is not yet loaded into memory! So the opening as above doesn't cost any noticable time!
(2) Now you can browse through the memory. In the moment when you access the file memory opened above, Windows automatically loads the requested bytes from the file. This is very fast and optimized by Windows. The find the last 10 lines, search backwards for #13#10. To search backwards you can e.g. use my function
http://help.madshi.net/Data/StringSearch.htm#PosPChar for this purpose. It's contained in my free package "madBasic", which you can download from my homepage for free including sources.
Sorry, have no time to write more sources or to test them...
Regards, Madshi.