Ich würd' mir was von TStringList ableiten:
Delphi-Quellcode:
TLogFile = class(TStringList)
private
FLoadCount: integer;
FFileName: string;
public
procedure UpDate;
procedure Refresh;
function IndexOfSubString(const SubStr: string; var Index: integer): integer;
function DeleteSubString(const SubStr: string): boolean;
property LoadCount: integer read FLoadCount;
property FileName: string read FFileName;
constructor Create(const AFileName: string);
end;
Delphi-Quellcode:
constructor TLogFile.Create(const AFileName: string);
begin
inherited Create;
FFileName:= AFileName;
FLoadCount:= 0;
Refresh;
end;
procedure TLogFile.Refresh;
begin
if FileExists(FFileName) then
begin
LoadFromFile(FFileName);
FLoadCount := Count;
end;
end;
procedure TLogFile.Update;
begin
if FileExists(FFileName) then
LoadFromFile(FFileName);
end;
function TLogFile.IndexOfSubString(const SubStr: string; var Index: integer): integer;
var
I: integer;
begin
UpDate;
Result := -1;
Index := 0;
for I:= FLoadCount to Count -1 do
begin
Index:= Pos(SubStr, Strings[I]);
if Index > 0 then
begin
Result := I;
Break;
end;
end;
end;
function TLogFile.DeleteSubString(const SubStr: string): boolean;
var
I, J: integer;
S: string;
begin
Result:= false;
I:= IndexOfSubString(SubStr, J);
if I > -1 then
begin
Result:= true;
S:= Strings[I];
System.Delete(S, J, Length(SubStr)); // ???
Strings[I]:= S;
end;
end;