[fpc-pascal] Seek with text file
Rik van Kekem
rik at graficalc.nl
Tue Apr 3 13:20:15 CEST 2018
Op 03-04-2018 13:04 schreef Anthony Walter:
> If the file is not to big you could simply write:
>
> procedure ChangeLastLine(const FileName, NewLine: string);
> var
> S: TStrings;
> begin
> S := TStringList.Create;
> try
> S.LoadFromFile(FileName);
> if S.Count > 0 then
> S[S.Count - 1] := NewLine
> else
> S.Add(NewLine);
> finally
> S.Free;
> end;
> end;
Don't forget the S.SaveToFile(FileName) just above the finally-line
otherwise nothing is saved back to the file :D
Rik
More information about the fpc-pascal
mailing list