* * *

Author Topic: Confused by TXMLPropStorage  (Read 668 times)

asdlinux

  • New member
  • *
  • Posts: 6
Confused by TXMLPropStorage
« on: July 02, 2018, 02:18:08 pm »
Hello all,

I am new to Lazarus and free pascal. I am sorry if this was asked before or if it is a stupid question. I have looked around and I can't figure out an aswer to my problem/question. I am trying to use TXMLPropStorage. Maybe I have got the whole idea wrong and I am using the wrong component.

I have created an application that contains a main form and a configuration form. In both i have a TXMLPropStorage control. In the configuration form I have 3 strings that i save. It works perfectly. When i open the configuration form, it displays the saved data and saves the edited strings.
Now to my "problem". In the main form I would like read these string to use them. I am doing this: 

Code: Pascal  [Select]
  1. procedure TMainWindow.XMLPropStorage1RestoreProperties(Sender: TObject);
  2. begin
  3.      IMAPServer:=XMLPropStorage1.StoredValue['IMAPServer'];
  4.      IMAPUserName:=XMLPropStorage1.StoredValue['IMAPUserName'];
  5.      IMAPPassword:=XMLPropStorage1.StoredValue['IMAPPassword'];
  6. end;  
  7.  

This is exactly the same working code in the config form. But when I run it in the main form... I get empty strings. Is it possible to read the saved strings from the configuration form and in that case how would i do that?
Thank you for your help!
Magnus

af0815

  • Full Member
  • ***
  • Posts: 158
Re: Confused by TXMLPropStorage
« Reply #1 on: July 02, 2018, 02:40:26 pm »
You can only read or write to the properties (have access)  inside the Event OnRestoreProperties or OnSaveProperties.

You can only call Save or Restore, the rest must be handled inside of the events.
 
regards
Andreas

asdlinux

  • New member
  • *
  • Posts: 6
Re: Confused by TXMLPropStorage
« Reply #2 on: July 02, 2018, 03:33:44 pm »
As far as i can tell, I am calling these in OnRestoreProperties event, But in the primary form. I do the same in the original form where it works.

af0815

  • Full Member
  • ***
  • Posts: 158
Re: Confused by TXMLPropStorage
« Reply #3 on: July 02, 2018, 03:48:21 pm »
You cannot call the OnRestoreProperties direkt, you can ONLY save or restore your info inside the event. If the event is not called from the XMLPropstorage itself, the data is not valid nor will be written.
You can only call eg. XMLPropstorage1.save to store or XMLPropstorage1.restore to receive the data.

See Notes in http://wiki.freepascal.org/TXMLPropStorage
« Last Edit: July 02, 2018, 03:51:26 pm by af0815 »
regards
Andreas

asdlinux

  • New member
  • *
  • Posts: 6
Re: Confused by TXMLPropStorage
« Reply #4 on: July 02, 2018, 04:33:15 pm »
If there is any help, Here is the generated xml file that TXMLPropStorage is saving. In both forms a in having connected events.

Code: XML  [Select]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CONFIG>
  3.   <TApplication>
  4.     <AccountConf IMAPServer="none.none.com" IMAPPassword="564219071a1c0d0c4157" IMAPUserName="Donald"/>
  5.   </TApplication>
  6. </CONFIG>    
  7.  

The names have been changed to protect the innocent :)
As long i do the events on the AccountConf form it works but not in the MainWindow form.

asdlinux

  • New member
  • *
  • Posts: 6
Re: Confused by TXMLPropStorage
« Reply #5 on: July 02, 2018, 04:34:53 pm »
Note: I am not firing the OnSavingProperties event in the main window because i am only interested in reading them.

Edson

  • Hero Member
  • *****
  • Posts: 929
Re: Confused by TXMLPropStorage
« Reply #6 on: July 02, 2018, 04:42:31 pm »
Take a look to https://github.com/t-edson/MiConfig

With this library you can Save/Restore propertties from/to disk:

Code: Pascal  [Select]
  1.  iniFile.FileToProperties;
  2.  iniFile.PropertiesToFile;
  3.  
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus