You are here

Load and Save using TStringList

Submitted by Asif Nowaj, Last Modified on 2019-11-22
TStringList provides easy to use LoadFromFile and SaveToFile methods that store a list of string from a text file and saves the list of string to a text file. Each line of the text file represents a string in the list.

procedure TForm1.Button2Click(Sender: TObject);
var
  tempStringList  : TStringList;
  fileName        : String;
begin
  fileName := 'c:\temp\myfile.txt';
  tempStringList := TStringList.Create;
  try
    tempStringList.LoadFromFile(fileName);    {Load string from text file}
    tempStringList.SaveToFile(ChangeFileExt(fileName, '.bak')); {save the text in a file with different file extension}
  finally
    tempStringList.Free;
  end;
end;


Discussion or Comment

If you have anything in mind to share, please bring it in the discussion forum here.

https://forum.everyething.com/delphi-f39/