TIniPropStorage with multiple forms - how? Bug? lazarus / 31-LCL ---------------------------------------------------------------------- poiuyt555 · 2013-04-18 11:27 Hi. I have 2 forms. I need: 1) Save SessionProperties from both forms in one file: myfile.ini 2) Save only when i close the main form, not when i close the second form! How can i do this? I try: place 2 inipropstorages on both forms, set inifilename=myfile.ini, set sessionproperties on both forms. Set inisection with main form=main, on second = second. But there was 2 problems: 1) The second form opens and closes often and always it saves settings to file. I have Kaspersky antivirus and every closing of secon form - it pauses to 1-2 sec. to save the settings - I don't need it. 2) Bug?: IniPropStorage - do not save well - checkbox1.checked from second form set to checkbox1 from main form... he confused inisections. ---------------------------------------------------------------------- howardpc · 2013-04-18 14:25 You only need one TIniPropStorage component, dropped on the main form. When your main form closes, get the inipropstorage component to do whatever you want. Here's a do-nothing example you can adapt, using a TIniPropStorage component named iniPS, main form Form1 and second form Form2: Code: [Select]//uses unit-containing-form2 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); var   i: Integer; begin   for i := 0 to Form1.ControlCount-1 do    IniPS.StoredValue['Form1.'+Form1.Controls[i].Name] := Form1.Controls[i].ClassName;   for i := 0 to Form2.ControlCount-1 do    IniPS.StoredValue['Form2.'+Form2.Controls[i].Name] := Form2.Controls[i].ClassName;   CloseAction:=caFree; end; ---------------------------------------------------------------------- poiuyt555 · 2013-04-18 15:29 Thanks, howardpc, i will try... Question: In what event TIniPropStorage write/read data? Ex, read before FormCreate? and save after FormClose? And if FormMain creates first... before Form2? And i need to load some values from file to Form2, ex. i need Save values - after main form close (it i understand - i will try), but load values: from MainForm - i need that they was set befor main form create, and values form second form - before formcreate of second form. ---------------------------------------------------------------------- BigChimp · 2013-04-19 05:38 Hope this helps: http://wiki.lazarus.freepascal.org/Event_order corrections/additions welcome. ---------------------------------------------------------------------- howardpc · 2013-04-19 13:29 The attached simple project shows one way you can figure out the order events are called, by implementing a simple logger. The code can be adapted to suit your needs On my system, the log from running and immediately closing the app is as follows: Code: [Select] [2013-04-19 14:21:13.401 Custom (0)]     Entering TForm1.FormCreate  [2013-04-19 14:21:13.401 Custom (0)] Leaving TForm1.FormCreate  [2013-04-19 14:21:13.401 Custom (0)] IniPSRestoringProperties event  [2013-04-19 14:21:13.401 Custom (0)] IniPSRestoreProperties event  [2013-04-19 14:21:13.417 Custom (0)]   *TForm2.FormCreate event*  [2013-04-19 14:21:13.417 Custom (0)] TForm1.FormShow event  [2013-04-19 14:21:13.463 Custom (0)] TForm1.FormActivate event  [2013-04-19 14:21:15.959 Custom (0)] TForm1.FormCloseQuery event  [2013-04-19 14:21:15.959 Custom (0)]     Entering TForm1.FormClose event  [2013-04-19 14:21:15.959 Custom (0)] Leaving TForm1.FormClose event  [2013-04-19 14:21:15.959 Custom (0)] IniPSSavingProperties event  [2013-04-19 14:21:15.975 Custom (0)] IniPSSaveProperties event  [2013-04-19 14:21:15.975 Custom (0)]   *TForm2.FormDestroy event*  [2013-04-19 14:21:15.975 Custom (0)] TForm1.FormDestroy event ---------------------------------------------------------------------- poiuyt555 · 2013-04-20 17:20 Thanks, howardpc, for your sample. Now i understand with the order of the events. But Form1 - main form and when i load values - form2 in not created yet. That is why i will try somehow solve it. Can we provide something like this: ips.StoredValues(or another property) = Form1.SessionProperties+Form2.SessionProperties. And place it somewhere, when Form2 has been created already? ---------------------------------------------------------------------- howardpc · 2013-04-20 20:23 Quote from: poiuyt555 on April 20, 2013, 07:20:38 pmCan we provide something like this: ips.StoredValues(or another property) = Form1.SessionProperties+Form2.SessionProperties. And place it somewhere, when Form2 has been created already? Could you not use Form2's OnClose event for this? ---------------------------------------------------------------------- poiuyt555 · 2013-04-23 04:34 Ok, i will see... But now i try to use again 2 inipropstorage (by 1 for every form), i just rename some checkboxes or ets... And i try not to close the second form, but do hide() command (by close button placed there).