Thank you for the advice and for the example. I don't know what is considered a 
large file.. these files can be maybe about 1000 lines long, most will be less, 
would this solution be suitable for files of this size?

Is Tstringlist something like an array of strings?


-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of 
Rik van Kekem
Sent: Tuesday, April 03, 2018 7:20 AM
To: fpc-pascal@lists.freepascal.org
Subject: Re: [fpc-pascal] Seek with text file

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

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to