Recent

Author Topic: (SOLVED] When are SessionProperties read and applied?  (Read 419 times)

fatmonk

  • Full Member
  • ***
  • Posts: 248
(SOLVED] When are SessionProperties read and applied?
« on: April 09, 2021, 08:09:31 pm »
I'm using a forms SessionProperties to store the state of various components on the form.

All is working well and everything is restoring correctly, however I need to act on one of the restored values when the application first starts.

I have added code to the Form's onCreate event to read the particular value of the restored control, but it seems that the SessionProperties have not been read, or at least not applied to the form controls, at this time.

OnShow and onActivate are not really appropriate as the could be fired at times other than the application starting - unless I add additional code with a justStarted Boolean and check that, which seems a bit hacky.

So, when are SessionProperties actually read and applied and is there a safe event for TForm that can reliably read from the restored values of controls on the form?

Thanks,

-FM
« Last Edit: April 10, 2021, 02:09:32 pm by fatmonk »

howardpc

  • Hero Member
  • *****
  • Posts: 3716
Re: When are SessionProperties read and applied?
« Reply #1 on: April 09, 2021, 08:32:12 pm »
Try overriding the form's protected Loaded method.

fatmonk

  • Full Member
  • ***
  • Posts: 248
Re: When are SessionProperties read and applied?
« Reply #2 on: April 09, 2021, 08:41:16 pm »
Thanks howardpc, but I think I've just found the perfect event...

TXMLPropStorage has a OnRestoreProperties event that fires when the properties have been restored.

I'm going to give that a go - I hadn't thought that the prop store itself would have events, doh!

-FM

fatmonk

  • Full Member
  • ***
  • Posts: 248
Re: When are SessionProperties read and applied?
« Reply #3 on: April 10, 2021, 02:09:00 pm »
Yup, the OnRestoreProperties event of TXMLPropStorage is exactly what I was looking for.

I was thinking that the properties of a form being restored would be an event for the TForm objects, but being an event of the property storage also makes sense.

Thanks howardpc, but I think I've just found the perfect event...

TXMLPropStorage has a OnRestoreProperties event that fires when the properties have been restored.

I'm going to give that a go - I hadn't thought that the prop store itself would have events, doh!

-FM

 

TinyPortal © 2005-2018