Skip to content

TElectronStringList

Below is a list of the methods for TElectronStringList. This class allows reading from files and writing to files.

Methods for TElectronStringList

Property Description
LoadFromFile(const FileName: string) Loads the contents of the file from the local file system into a stringlist.
SaveToFile(const FileName: string) Writes the contents of the stringlist into a file on the local file system.

Example 1: Open file contents using TElectronStringList and TElectronOpenDialog

procedure TForm1.OpenDialogCallback(FileNames: TJSElectronStringDynArray);
var
  sl: TElectronStringList;
begin
  if Length(FileNames) > 0 then
  begin
    sl := TElectronStringList.Create;
    try
      sl.LoadFromFile(FileNames[0]);
      MEditor.Lines.Assign(sl);
    finally
      sl.Free;
    end;
  end;
end;

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  ElectronOpenDialog1.Execute(@OpenDialogCallback);
end;

Example 2: Save to file using TElectronStringList and TElectronSaveDialog

procedure TForm1.SaveDialogCallback(FileName: string);
var
  sl: TElectronStringList;
begin
  if FileName <> '' then
  begin
    sl := TElectronStringList.Create;
    try
      sl.Assign(WebMemo1.Lines);
      sl.SaveToFile(FileName);
    finally
      sl.Free;
    end;
  end;
end;

procedure TForm1.WebButton2Click(Sender: TObject);
begin
  ElectronSaveDialog1.Execute(@SaveDialogCallback);
end;