SessionProperties defaults to IniStorage and causes EXML errors. lazarus / 21-General ---------------------------------------------------------------------- vfclists · 2021-02-17 03:15 I am using the SessionProperties in forms and when I run the application I get an EXMLReadError because the xml file does not exist. When the application is closed the settings are saved in the INI file format no matter what, even though I haven't specified what file type should be used. Is there some way to specify the format of the SessionProperties, or is it a bug? I think when it comes to the SessionProperties you should be able to specify the filename as well as the file type, whether XML, JSON or INI. ---------------------------------------------------------------------- wp · 2021-02-17 09:04 SessionProperties cooperate with one of the *PropStorage components on the Misc palette: https://wiki.freepascal.org/TXMLPropStorage. The kind of PropStorage component selected determines the kind of the data file, ini or xml. ---------------------------------------------------------------------- vfclists · 2021-02-17 14:00 Quote from: wp on February 17, 2021, 10:04:10 amSessionProperties cooperate with one of the *PropStorage components on the Misc palette: https://wiki.freepascal.org/TXMLPropStorage. The kind of PropStorage component selected determines the kind of the data file, ini or xml. The problem is with the poor internal design and initial configuration. It shouldn't create an error on a session properties file which doesn't exist or is empty, or is an INI file rather than the XML file it seems to expect. That is simply careless. As I said it defaults to using the INI format, and doesn't offer you a way to specify that you want an XML file instead. I will create a new empty project to go through the whole process again. What I need to know now is how the settings are read at start at time and saved at closing time. Can you guide me to the sources of TForm or TApplication where that code is executed? ---------------------------------------------------------------------- wp · 2021-02-17 14:18 I am afraid you are doing something wrong. Just made a little demo with a few controls, added some properties to the session properties, with no *PropStorage components available, and ran the application several times --> no error. Without PropStorage component the SessionProperties should not attempt to write anything to an ini/xml file.  With the mere addition of an XMLPropStorage component everything works correctly, and the stored properties are stored to and retrieved from the xml file automatically. So, what are you doing exactly? Please post a sample project. ---------------------------------------------------------------------- vfclists · 2021-02-17 15:44 Quote from: wp on February 17, 2021, 03:18:18 pmI am afraid you are doing something wrong. Just made a little demo with a few controls, added some properties to the session properties, with no *PropStorage components available, and ran the application several times --> no error. Without PropStorage component the SessionProperties should not attempt to write anything to an ini/xml file.  With the mere addition of an XMLPropStorage component everything works correctly, and the stored properties are stored to and retrieved from the xml file automatically. So, what are you doing exactly? Please post a sample project. I just did what you did and it worked fine, but the design should use explicit code instead of using some undocumented magic in the background. It should be possible to accomplish what is done by adding XMLPropStorage component to the form in code. It seems that at runtime the process of initializing the XMLPropStorage component  on the form looks up the settings file based on the application name in the home directory and tries to load settings from it automatically, without even checking that is valid XML, or whether it was created by the application itself. This will be a problem when you are running multiple instances of the same program or another application uses the same application name. It is not following the principle of least surprise. What if I want to use a different session file name, or store in a different location, eg, under ~/.config/applicationname? In an earlier test I noticed that the other forms shared the the same session properties file. Is the RootNodePath property the way to distinguish the settings used by the different forms? At the end of the day it simply needs better documentation, and there should be a way to distinguish global application properties from properties which are specific to some forms and some different sessions. ---------------------------------------------------------------------- wp · 2021-02-17 16:32 Quote from: vfclists on February 17, 2021, 04:44:10 pmI just did what you did and it worked fine, but the design should use explicit code instead of using some undocumented magic in the background.That's the "magic" of Lazarus. All controls and components have a lot of code running under the hood. Quote from: vfclists on February 17, 2021, 04:44:10 pmIt should be possible to accomplish what is done by adding XMLPropStorage component to the form in code. I still don't know what you want to achieve. Create the XMLPropStorage at runtime? When I delete the XMLPropStorage component from the "_with_storage" demo of the previous post and create the XMLProgStorage at runtime in the OnCreate event of the form, everything is correct, too. What is the problem? Again, post your code in a small demo application. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  XMLPropStorage := TXMLPropStorage.Create(self);end; Quote from: vfclists on February 17, 2021, 04:44:10 pmIt seems that at runtime the process of initializing the XMLPropStorage component  on the form looks up the settings file based on the application name in the home directory and tries to load settings from it automatically, without even checking that is valid XML, or whether it was created by the application itself. This will be a problem when you are running multiple instances of the same program or another application uses the same application name. I don't know about the error checks (in fact, I use my own storage routines in my own applications), and I cannot comment on issues with muliple instances. I suppose every instance will use the same xml file. Maybe you must give its session its own RootNodePath if you want to distinguish between sessions. But which session data will be used when the program starts the next time? For doing such specific tasks you may be better off when you write your own storage methods. Quote from: vfclists on February 17, 2021, 04:44:10 pmWhat if I want to use a different session file name, or store in a different location, eg, under ~/.config/applicationname?Did you see the "Filename" property of the XMLPropStorage component? Quote from: vfclists on February 17, 2021, 04:44:10 pmIn an earlier test I noticed that the other forms shared the the same session properties file. Is the RootNodePath property the way to distinguish the settings used by the different forms?No the RootNodePath is the xml path to the root of the session properties in the xml file. This is useful because you can store additional information in the xml file, beside the session properties. Multiple forms in the same xml storage file are distinguished by their name. I don't know how the XMLstorage behaves when forms are created at runtime - as I said I am using my own storage routines where I know exactly when what is happening. ---------------------------------------------------------------------- vfclists · 2021-02-17 16:45 I think I will just have to experiment with it to get some clarity on how the process works. @wp Do you know if the XXXPropStorage components apply the settings after the form has loaded with the original settings, or do they intercept the loading of the form and apply the changes? I am looking for a way to update GUI components by streaming the changes to the properties over the network or via a pipe and I wonder if the XXXPropStorage applies changes after the components are fully loaded. If they are changed after the form is fully loaded then I can look it up and adapt that code to modifying properties at runtime. ---------------------------------------------------------------------- lucamar · 2021-02-17 18:30 Quote from: vfclists on February 17, 2021, 05:45:52 pmDo you know if the XXXPropStorage components apply the settings after the form has loaded with the original settings, or do they intercept the loading of the form and apply the changes? First the form is created and the controls (and its "default" properties) loaded from the form resource and then, if it's Active, xxxPropStorage is used to set the properties stored in it. Note that the form won't yet be visible while all this is taking place so there should be no "form appears one way and then changes" problem. Only, if there are many properties to restore from xxxPropStorage and changing them involves many operations (e.g. if AutoSize is set on on many controls and their contents change, or similar) it might take a little time for the form to show, but this is usually negligible. Quote from: vfclists on February 17, 2021, 05:45:52 pmIf they are changed after the form is fully loaded then I can look it up and adapt that code to modifying properties at runtime. You don't need to do that: just set a handler for OnRestoreProperties and do what you need there. One of my apps, for example, use it to create and populate some Memos from several separate files whose names are stored in a TXMLPropStorage (using an OnSaveProperties handler) ---------------------------------------------------------------------- wp · 2021-02-17 18:39 Since the XMPPropStorage is a component like any other component it is streamed and cannot be active before the form is fully loaded. Its ancestor TFormPropertyStorage, in the Forms unit, installs a "FormCreate" handler which becomes active in the AfterConstruction method: it calls its method Restore which applies the properties from the xml file to the form. So, in total: at first the form reads and applies all the properties defined in the lfm form, then the PropStorage components become active and apply the xml settings.