<div dir="ltr"><div class="gmail_extra">If the file is not to big you could simply write:</div><div class="gmail_extra"><br></div><div class="gmail_extra">procedure ChangeLastLine(const FileName, NewLine: string);</div><div class="gmail_extra">var</div><div class="gmail_extra">  S: TStrings;</div><div class="gmail_extra">begin</div><div class="gmail_extra">  S := TStringList.Create;</div><div class="gmail_extra">  try</div><div class="gmail_extra">    S.LoadFromFile(FileName);</div><div class="gmail_extra">    if S.Count > 0 then</div><div class="gmail_extra">      S[<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">S.Count - 1</span>] := NewLine</div><div class="gmail_extra">    else</div><div class="gmail_extra">      S.Add(NewLine);</div><div class="gmail_extra">  finally</div><div class="gmail_extra">    S.Free;</div><div class="gmail_extra">  end;</div><div class="gmail_extra">end;</div></div>