I need to find a certain string, in a text file, from bottom (the end of the line). Once the string has been found, the function exit.
Here is my code, which is working fine. But, it is kind of slow. I meant, I run this code every 5 seconds. And it consumes about 0.5% to 1% CPU time. The text file is about 10 MB.
How to speed this up? Like, really fast and it doesn't consume much CPU time.
function TMainForm.GetVMem: string;
var
TS: TStrings;
sm: string;
i: integer;
begin
TS := TStringList.Create;
TS.LoadFromFile(LogFileName);
for i := TS.Count-1 downto 0 do
begin
Application.ProcessMessages;
sm := Trim(TS[i]);
if Pos('Virtual Memory Total =', sm) > 0 then
begin
Result := sm;
TS.Free;
exit;
end;
end;
Result := '';
TS.Free;
end;