Contains a component that stores Form Session Properties in JSON format.

In this unit you can find an implementation of a name/value pair storage container using JSON (JavaScript Object Notation) format.

This container will get the Form's Session Properties that you setup in TForm.SessionProperties and read/write them on the file you specify on TJSONPropStorage.JSONFileName .

This unit contains the implementation of a path/value pair generic container in JSON format. See package: fcl-json. Implements the base class used to store session properties to a file in JSON format.

TCustomJSONPropStorage is a TFormPropertyStorage descendant which defines a class used to store session properties for a form or frame to a file using JSON (JavaScript Object Notation) format. It extends the ancestor class with properties and methods needed to access the JSON storage mechanism (TJSONConfig) for the class instance.

Use the SessionProperties property in the TForm (or TFrame) instance which owns the class to define the component and property names written to the JSON storage mechanism.

Use JSONFileName to specify the path and file name to the file where the JSON content for the session properties is stored.

Use RootObjectPath to specify the path to the JSON object where the session properties is stored in the JSON file.

Use Formatted to control whether formatting options for the JSONConfig file are enabled for the storage mechanism.

TCustomJSONPropStorage includes overridden methods used to read, write, and maintain entries in the JSON storage mechanism.

Do not create instances of TCustomJSONPropStorage; use the TJSONPropStorage descendant instead.

TFormPropertyStorage
Gets the value for the JSONFileName property. TCustomJSONPropStorage.JSONFileName Value for the JSONFileName property. Returns the name of the RootSection for the storage mechanism.

RootSection is an overridden String function used to return the section where the JSON content is stored in the JSON file. It ensures that the value in RootObjectPath is used (when assigned). When omitted, the inherited method is called to get the JSON object path for components in the hierarchy for Root.

The return value contains the JSON notation for the path name, like: 'TApplication/Form1' or 'TApplication/Frame1'.

The current value for the RootSection property. Gets the value for the Formatted property. The current value for the Formatted property. Sets the value for the Formatted property. New Boolean value for the Formatted property. Converts component/property names using '.' delimiters to the '/' delimiter used for the JSON notation in the JSONConfig storage mechanism.

fpjson Reference

FCL JSON

The path to be fixed. The fixed path is returned with '.' replaced by '/'. TJSONConfig instance used to store path/value pairs.

JSONConf is a read-only TJSONConfig property which provides access to the JSON storage mechanism used in the class instance.

JSONConf does not have any of the formatting options assigned in the property. You must assign values to the FormatOptions property in JSONConf to enable the feature when Formatted is set to True. You can use the predefined constant values like AsCompressedJSON or AsCompactJSON.
Ensures that the TJSONConfig storage mechanism for the class instance is allocated and configured when needed.

Creates the TJSONCOnfig instance in JSONConf if it has not already been allocated, or when the value in ReadOnly differs from the value used when the storage mechanism was created. Uses values from Formatted and GetJSONFileName to configure the JSONConf member. Increments the internal usage counter for the storage mechanism.

StorageNeeded is called from methods like: Save, Restore, SaveProperties, RestoreProperties, ReadString, WriteString, ReadInteger, WriteInteger, and EraseSections.

See FreeStorage for the actions performed when the JSON storage mechanism in JSONConf is no longer needed.

True to create the storage mechanism using read-only permission. Frees the TJSONConfig storage mechanism when no longer needed.

Frees the JSON storage mechanism in JSONConf when the internal usage counter reaches 0 (zero).

FreeStorage is called from methods like: Save, Restore, SaveProperties, RestoreProperties, ReadString, WriteString, ReadInteger, WriteInteger, and EraseSections.

See StorageNeeded for the actions performed when the JSON storage mechanism in JSONConf is allocated and configured for the class instance.

Performs actions needed to read the value for the specified section and identifier as a String type.

DoReadString is an overridden String function used to implement the ReadString method in the TCustomPropertyStorage ancestor. DoReadString ensures that the value for Section and Ident is converted from the UTF-16 encoding (UnicodeString) used in JSONConf (TJSONConfig) to the UTF-8 encoding used in the return value.

The section to be read in the method. The identifier to be read in the method. Default value returned for the specified section and identifier when either the section or identifier was not found in JSONConf. Returns the value for the section/ident requested. Performs actions needed to write the specified Section and Ident to the JSON storage mechanism as a String type.

DoWriteString is an overridden method used to implement the WriteString method in the TCustomPropertyStorage ancestor. DoWriteString ensures that Value is converted from the UTF-8 encoding used in the argument to the UTF-16 encoding (UnicodeString) used in JSONConf (TJSONConfig).

The Value argument is stored using the identifiers in the Section and Ident parameters. They are converted from the their representation as dotted-LCL component names and properties to the '/'- delimited XPATH-like notation. For example:

'TApplication', 'Form1.Width' => 'TApplication/Form1/Width' Please note that any component which does not have an explicit value in its Name property defaults to the ClassName for the component, like 'TApplication'.

Use active to enable or disable read and write operations to the JSON property storage mechanism.

TCustomPropertyStorage.WriteString TCustomPropertyStorage.Active
Name for the section where the value is stored. Name for the identifier where the value is stored. String value stored in the method. Performs actions needed to remove the entry (and all of its child entries) at the specified path in the JSON storage.

DoEraseSections is an overridden method used to remove the named section and all of the identifiers stored at the path in ARootObjectPath. It implements the EraseSections method in the TCustomPropertyStorage ancestor.

DoEraseSections calls FixPath to convert dotted component and property names in ARootObjectPath to their XPATH-like notation used to access the elements in JSONConf. For example: 'TApplication.Form1' becomes 'TApplication/Form1'. The DeletePath method in JSONConf is called to remove the JSON element and any identifiers nested below the target element.

Use Active to enable or disable read and write operations to the JSON property storage mechanism.

TCustomPropertyStorage.EraseSections TCustomPropertyStorage.Active
The path to the JSON element (section) removed in the method. Name of the file where the session property names and values are saved in JSON format.

JSONFileName is a String property which contains the name for the JSON file used to read and write SessionProperties values in the class instance. Its value is used in GetJSONFileName to determine the file name used in JSONConf when the storage mechanism is allocated for the class instance. An explicit value assigned to the property is used when available.

When not assigned (''), a file name based on the executable file name is used. For example:

For Windows
The value in Application.Executable is converted to '.json' file extension and used as the JSON file name, like: 'D:\apps\project1.json'.
For UNIX-like platforms
The value in Application.Executable is converted to a hidden file in the HOME directory for the user, like: '~/babayaga/.project1'.
Name of the root JSON object in the JSON file where session properties are stored.

RootObjectPath is a String property with the path to the JSON element where the SessionProperties for the form (or frame) are stored in the JSON file. When assigned, its value is used as the RootSection for the class instance. When not assigned, the component name hierarchy up to the Root object is used.

Use JSONFileName to specify the name for the JSON file used to store session property values.

Use Active to enable or disable read or write operations using the JSON storage mechanism.

TCustomPropertyStorage.RootSection
Controls whether formatted JSON is emitted in the JSONConf storage mechanism.

Formatted is a Boolean property which enables or disables formatted output for the JSON written to JSONFileName. When enabled, the JSON objects and elements are written with one named item per line and indenting for nested name/value pairs. For example:

{ "TApplication" : { "Form1" : { "DBGrid1_AlternateColor" : "-2147483643", "Form1_Height" : "723", "Form1_Left" : "1215", "Form1_SessionProperties" : "DBGrid1.AlternateColor;Height;Left;SessionProperties;Top;Width", "Form1_Top" : "57", "Form1_Width" : "320" } } }

If not enabled, all JSON values are generated on a single line with only whitespace between the JSON name and values.

The property value is assigned to JSONConf when the storage mechanism is allocated for the class instance in StorageNeeded.

TCustomPropertyStorage.Active
Implements the final class for the JSON Form Session Properties storage.

TJSONPropStorage is a TCustomJSONPropStorage descendant which implements a class used to store session properties for a form or frame to a file using JSON (JavaScript Object Notation) format. It sets the visibility for properties introduced in ancestor classes.

Use the SessionProperties property in the TForm (or TFrame) instance which owns the class to define the component and property names written to the JSON storage mechanism.

Use JSONFileName to specify the path and file name to the file where the JSON content for the session properties is stored.

Use RootObjectPath to specify the path to the JSON object where the session properties is stored in the JSON file.

Use Formatted to control whether formatting options for the JSON config file are enabled for the storage mechanism.

TForm.SessionProperties TINIPropStorage TXMLPropStorage
Registers TJSONPropStorage on the 'Misc' tab of the component palette.