[fpc-devel] Rather large flaw in TJSONConfig component

Michael Van Canneyt michael at freepascal.org
Mon Jun 21 16:33:26 CEST 2010



On Mon, 21 Jun 2010, Graeme Geldenhuys wrote:

> 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.

The same happens if you use .INI files. I don't see this as a problem.

The best way to avoid it is to create/destroy the config object after use.
When the form is opened, you create an ini/json/whatever file object and
read the data. Then destroy. When The form is closed, again create the file
object (it should read the latest version of the file then) and then save 
changed values and destroy.

Likewise for a database application. Unless you take care of transaction
support, 2 users editing a record will overwrite each other's changes,
unless the programmer explicitly takes care of this.

In 12 years that our apps run, we used the system 'last writer wins' and 
no single user has complained yet about this.

Michael.



More information about the fpc-devel mailing list