Recent

Author Topic: [SOLVED] How to save user-defined Form settings?  (Read 1130 times)

fmc

  • New Member
  • *
  • Posts: 27
[SOLVED] How to save user-defined Form settings?
« on: October 21, 2019, 10:19:31 pm »
I use an *.ini file to save adjustments the end-user might make to grid cell widths, panel height/width (where a splitter is used to adjust panel size), etc. I also write to that *.ini file Form height/width when the user makes adjustments. This works. BUT...the next time that Form is called up, it's height/width gets reset (and written to the *.ini file via the Form.OnResize event) to design-time settings made in the Object Inspector and voids the settings set by the user.

One solution is to create a table for the Forms, write the Form's height/width set by the user and use those settings each time the Form is opened. But are there alternatives to this approach? 
« Last Edit: October 23, 2019, 09:04:13 pm by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

jamie

  • Hero Member
  • *****
  • Posts: 2083
Re: How to save user-defined Form settings?
« Reply #1 on: October 21, 2019, 10:59:51 pm »
The best way to do that is write the settings in the destructor of the form so at closing time is when the INI file gets updated.

 Unless you have a need for some remote app to constantly monitor the current size of the form it's best to not write to the INI each time the LCL wiggles.

 Also, I normally set the form size values within the constructor on startup, But beware there are some combinations of how the form will show initially will ignore your attempt to change the actual size values during the construction of the form. For this I have saved the current size to a temp area and then force the show position into Designed Time state in case its not and if the parameters don't exists in the INI for the first time I use the current values.

 So if you use lets say poDefault when the form is coming up you can get the current values and then change the Position property to poDesigned so that you can make changes to it.
 
 otherwise, you can't change it.



Number 1 at blue screen app creations!

fmc

  • New Member
  • *
  • Posts: 27
Re: How to save user-defined Form settings?
« Reply #2 on: October 21, 2019, 11:58:32 pm »
That did it, jamie. My issue was that I was writing the height and width of the form to the *.ini file "each time the LCL wiggled". I took it out of the OnResize event and tied it to FormClose, and now the form comes up each time the way the user expects. Thanks.
« Last Edit: October 23, 2019, 09:02:00 pm by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

Thaddy

  • Hero Member
  • *****
  • Posts: 9183
Re: [SOLVED] How to save user-defined Form settings?
« Reply #3 on: October 22, 2019, 08:10:58 am »
A cleaner way is to do it in the OnCloseQuery event, so you do not clobber a destructor.
also related to equus asinus.

fmc

  • New Member
  • *
  • Posts: 27
Re: [SOLVED] How to save user-defined Form settings?
« Reply #4 on: October 23, 2019, 02:12:37 am »
A cleaner way is to do it in the OnCloseQuery event, so you do not clobber a destructor.

"Sometimes you can't see the trees for the forest."

Thanks for that info, Thaddy. I didn't think of it in those terms, but a lot of things are being shutdown when the forms close. And piggybacking this on an event like you suggested makes perfect sense.

Thanks, man.
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4