Read INI lazarus / 21-General ---------------------------------------------------------------------- Pe3s · 2021-11-08 17:59 Hello, I found the code on the internet Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SaveSettings;begin  myINI := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));  try    Assert(myINI <> nil);    if HandleAllocated then    begin      Wp.Length := SizeOf(TWindowPlacement);      GetWindowPlacement(Handle, @Wp);       myINI.WriteInteger('Placement', 'Top', Wp.rcNormalPosition.Top);      myINI.WriteInteger('Placement', 'Left', Wp.rcNormalPosition.Left);      myINI.WriteInteger('Placement', 'Width', Wp.rcNormalPosition.Right - Wp.rcNormalPosition.Left);      myINI.WriteInteger('Placement', 'Height', Wp.rcNormalPosition.Bottom - Wp.rcNormalPosition.Top);       myINI.WriteBool('Placement', 'Maximized', WindowState = wsMaximized);    end;  finally    myINI.Free;  end;end; how can i read these settings Thank you ---------------------------------------------------------------------- ArtLogi · 2021-11-08 21:21 You can also do it with RTL functions (as filehandling and string functions) and dynamic arrays, but that is the hard way, to get everything trapped on events and more so without bugs, when there is a ready made tool for ini-files. I can not recommend... only advantage is that it is easier to remember the primitive functions than advanced library etc. ---------------------------------------------------------------------- Handoko · 2021-11-09 06:40 I quickly written a short demo: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, Forms, Controls, StdCtrls, IniFiles; type   { TForm1 }   TForm1 = class(TForm)    btnLoad: TButton;    btnSave: TButton;    chkAutosave: TCheckBox;    procedure btnLoadClick(Sender: TObject);    procedure btnSaveClick(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);  private    procedure SavePosition;    procedure LoadPosition;  end; const  ConfigFile = 'config.ini'; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  if chkAutosave.Checked then    SavePosition;end; procedure TForm1.FormCreate(Sender: TObject);begin  LoadPosition;end; procedure TForm1.btnLoadClick(Sender: TObject);begin  LoadPosition;end; procedure TForm1.btnSaveClick(Sender: TObject);begin  SavePosition;end; procedure TForm1.SavePosition;var  Config: TIniFile;begin  Config := TIniFile.Create(ConfigFile);  try    Config.WriteInteger('Position', 'Top', Self.Top);    Config.WriteInteger('Position', 'Left', Self.Left);    Config.WriteInteger('Position', 'Width', Self.Width);    Config.WriteInteger('Position', 'Height', Self.Height);  finally    Config.Free;  end;end; procedure TForm1.LoadPosition;var  Config: TIniFile;begin  Config := TIniFile.Create(ConfigFile);  try    Self.Top    := Config.ReadInteger('Position', 'Top', 100);    Self.Left   := Config.ReadInteger('Position', 'Left', 100);    Self.Width  := Config.ReadInteger('Position', 'Width', 320);    Self.Height := Config.ReadInteger('Position', 'Height', 240);  finally    Config.Free;  end;end; end. 'Self' in the code above can be safely removed, but to make it clear (for newbies), I kept them. ---------------------------------------------------------------------- Pe3s · 2021-11-09 07:09 @Handoko Thank you for the demo.  the problem with ini is that I wanted to make the program remember the form size setting additionally as we maximize the form so that it can write and read.  after returning to the normal window to return to the established dimensions. ---------------------------------------------------------------------- Ally · 2021-11-09 09:06 Hello Pe3s, with RestoredTop ... and WindowState it works. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, Forms, Controls, StdCtrls, IniFiles; type   { TForm1 }   TForm1 = class(TForm)    btnClose: TButton;    procedure btnCloseClick(Sender: TObject);    procedure FormShow(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);  private    { private declarations }  public    { public declarations }  end; const  ConfigFile = 'config.ini'; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.btnCloseClick(Sender: TObject);begin  Close;end; procedure TForm1.FormShow(Sender: TObject);var  Config: TIniFile;begin  Config := TIniFile.Create(ConfigFile);  try    Top := Config.ReadInteger('Position', 'Top', 100);    Left := Config.ReadInteger('Position', 'Left', 100);    Width := Config.ReadInteger('Position', 'Width', 320);    Height := Config.ReadInteger('Position', 'Height', 240);    WindowState := TWindowState(Config.ReadInteger('Position', 'WindowState', 0));  finally    Config.Free;  end;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  Config: TIniFile;begin  Config := TIniFile.Create(ConfigFile);  try    Config.WriteInteger('Position', 'Top', RestoredTop);    Config.WriteInteger('Position', 'Left', RestoredLeft);    Config.WriteInteger('Position', 'Width', RestoredWidth);    Config.WriteInteger('Position', 'Height', RestoredHeight);    Config.WriteInteger('Position', 'WindowState', Integer(WindowState));  finally    Config.Free;  end;end; end. ---------------------------------------------------------------------- Pe3s · 2021-11-09 16:56 Thank you, that's what I meant. regards ---------------------------------------------------------------------- Tony Stone · 2021-11-20 00:24 May be worth taking a look at sessionProperties as well. https://wiki.lazarus.freepascal.org/TXMLPropStorage Quote from: Pe3s on November 09, 2021, 08:09:44 am@Handoko Thank you for the demo.  the problem with ini is that I wanted to make the program remember the form size setting additionally as we maximize the form so that it can write and read.  after returning to the normal window to return to the established dimensions. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-20 00:52 Hey Pe3s, The code you found is a tad hands on and there's loads you have to do by hand, which can be error prone. Like @TonyStone mentioned, a better way of doing it is using the T[XML|INI|JSON]PropStorage. Opting for any of those, you can have your settings automatically loaded at start up and automatically stored upon close. And in one of 3 flavours: XML, INI, JSON. The component even has a generic "bag" of options you can store that are not RTTI related. I tend to use the JSON one(Disclaimer: I'm the author and asked the dev to include it on the sources) since I had an itch to scratch and I did scratch it Hope this gives you a bit more options. Cheers, Gus ---------------------------------------------------------------------- Pe3s · 2021-11-20 11:40 Thank you ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-20 21:44 Hey Pe3s, Quote from: Pe3s on November 20, 2021, 12:40:35 pmThank you Quite welcome my fellow Pascal enthusiast. Cheers, Gus