Forum > Windows (32/64)

Persistent properties

(1/2) > >>

Is there an easy way to store properties between program invocations?  Like when the user re-positions a form, or widens it, and you want the form to be where s/he last left it?

I used to use iniFiles, but I imagine some progress has been made.




--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, IniFiles; type   { TForm1 }   TForm1 = class(TForm)    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);  end; const  IniFile         = 'Config.ini';  PositionSection = 'Position';  SizeSection     = 'Size';  LeftID          = 'Left';  TopID           = 'Top';  WidthID         = 'Width';  HeightID        = 'Height'; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  IniData: TIniFile;begin  IniData := TIniFile.Create(IniFile);  IniData.WriteInteger(PositionSection, LeftID, Left);  IniData.WriteInteger(PositionSection, TopID, Top);  IniData.WriteInteger(SizeSection, WidthID, Width);  IniData.WriteInteger(SizeSection, HeightID, Height);  IniData.Free;end; procedure TForm1.FormCreate(Sender: TObject);var  IniData: TIniFile;begin   Constraints.MinHeight := 240;  Constraints.MinWidth  := 320;  Constraints.MaxHeight := 1080;  Constraints.MaxWidth  := 1920;   if FileExists(IniFile) then  begin    IniData := TIniFile.Create(IniFile);    Left    := IniData.ReadInteger(PositionSection, LeftID, 0);    Top     := IniData.ReadInteger(PositionSection, TopID, 0);    Width   := IniData.ReadInteger(SizeSection, WidthID, 320);    Height  := IniData.ReadInteger(SizeSection, HeightID, 240);    IniData.Free;  end; end; end.

There are also classes like TIniPropStorage, TJSONPropStorage, and TXMLPropStorage.
Demos in: examples/propstorage.

Also, one can use TRegistry to store the data.


--- Quote from: dsiders on March 30, 2024, 04:00:53 pm ---There are also classes like TIniPropStorage, TJSONPropStorage, and TXMLPropStorage.
Demos in: examples/propstorage.

--- End quote ---
And there is a tutorial-like wiki-article:; it is for XMLPropStorage, but can be applied to IniPropStorage and JSONPropstorage in the same way.


[0] Message Index

[#] Next page

Go to full version