Hi,
Attached is a patch which extents the jsonconf test suite. The new test highlights a rather big flaw in the workings of the TJSONConfig component. This issue might even apply to TXMLConfig component too - I haven't looked yet.
This came about in the discussion in the Lazarus mailing list about Lazarus IDE storing application settings in XML files. I investigated the idea of replacing my usage of INI files for storing application settings with JSON files (TJSONConfig) instead. In each of my applications, I store all GUI Form state (position, size, etc) all in one "application settings" file - each form has it's own XXXFormState section.
In the test TestConcurrency I simulate two forms being opened - each form contains a TJSONConfig component. When I close one form it writes the state information. When I close the second form, it overwrites the whole JSON file, wiping out the first form's information completely. This is rather dangerous behaviour!
I see 3 solutions here:
1) Use a Singleton with TJSONConfig so we only have one instance of TJSONConfig per application.
2) Extend TJSONConfig so that it is more intelligent when writing to a file, and only writes the path information it modified or created.
3) When using one TJSONConfig per form, force the developer to use a different .json file for each form.
Any comments or alternative solutions? I know XMLConfig and JSONConfig are not documented yet, but if nothing is going to be done about this concurrency issue I highlighted, then the documentation must clearly state the dangerous behaviour of these components.
Regards,
- Graeme -
