W
W
White_Bambie2019-02-05 17:25:09
Delphi
White_Bambie, 2019-02-05 17:25:09

How to save form content in ini file?

There is a memo on the form, you need to save the contents of the memo to the INI file, but do it through the SaveDialog with the given name. Then open this or another ini using OpenDialog.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2019-02-05
@White_Bambie

Since there are many descriptions on the network, I will give the first one in Russian: TIniFile or Working with INI files in the same place.
Since the ini file is not just text, but a structure, loops are needed.

unit
const
  siSection = 'Memo';
  siCount   = 'Count';
  siLine    = 'Line';
…
var f: TIniFile; i: Integer;
begin
  if SaveDialog1.Execute then begin
    f := TIniFile.Create( SaveDialog1.FileName );
    f.WriteInteger( siSection, siCount, Memo1.Lines.Count );
    for i:= 1 to Memo1.Lines.Count
      do f.WriteString( siSection, siLine + IntToStr(i), Memo1.Lines[i-1] );
    f.Free;
  end;
end;
…
var f: TIniFile; i: Integer;
begin
  if OpenDialog1.Execute then begin
    f := TIniFile.Create( OpenDialog1.FileName );
    Memo2.Lines.Clear;
    for i:= 1 to f.ReadInteger( siSection, siCount, 1 )
      do Memo2.Lines.Add( f.ReadString( siSection, siLine + IntToStr(i), '' ));
    f.Free;
  end;
end;

K
kalapanga, 2019-02-05
@kalapanga

And what's the problem?

SaveDialog1.DefaultExt :='ini';
If SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);
Well, read the same way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question