[Overview][Classes][Procedures and functions][Index] | Reference for unit 'XMLPropStorage' (#lcl)

# TCustomXMLPropStorage

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Implements the base class for XML storage of Form Session properties.

## Declaration

Source position: xmlpropstorage.pas line 38

`type TCustomXMLPropStorage = class(TFormPropertyStorage)`
`protected`
`function GetXMLFileName; virtual;` |  | Gets the value for the FileName property.
`function RootSection; override;` |  | Returns the name of the RootSection.
`function FixPath(); virtual;` |  | Turns '.' notation into '/' notation for the XPATH-like implementation in XMLConf.
`property XMLConfig: TPropStorageXMLConfig; [r]` |  | Property to access the XML configuration file where the content is stored.
`public`
`procedure StorageNeeded(); override;` |  | Ensures the underlying storage object is allocated at run-time.
`procedure FreeStorage; override;` |  | Frees the underlying storage object for the class instance.
`function DoReadString(); override;` |  | Implements reading of a value from the underlying storage container.
`procedure DoWriteString(); override;` |  | Implements writing of a string value to the underlying storage container.
`procedure DoEraseSections(); override;` |  | Erases a section from the underlying storage container.
`property FileName: string; [rw]` |  | Name of the file where the property data is saved in XML format.
`property RootNodePath: string; [rw]` |  | Path to the root node in the XML file.
`end;`

## Inheritance

`TCustomXMLPropStorage` |  | Implements the base class for XML storage of Form Session properties.
`TFormPropertyStorage` |  | TFormPropertyStorage - class for storage of a Form's properties.
`TControlPropertyStorage` |  | Implements the abstract ancestor class used to get the property list for a control.
`TCustomPropertyStorage` |  | Defines a container used to Save and Restore property values.
`TComponent`
?
`TObject`

## Description

TCustomXMLPropStorage is a TFormPropertyStorage descendant used to save or restore properties values in an XML file. It introduces new properties, methods, and members needed to read or write values in an XML file.

Values read or written using the class are defined in the SessionProperties for a TForm or a TFrame instance. At design-time, use the SessionProperties property editor in the Object Inspector to maintain the property names. At run-time, the property names can be assigned using a string like:

    Form1.SessionProperties := 'Width;Height;Image1.Width';

Use the FileName property to specify where the XML content is stored.

Use the RootNodePath property to specify the path to a node in the XML document where the XML content is stored.

At run-time, default handler routines (attached to the parent form) are used to Save or Restore the content in the XML file when the form is created or destroyed.

Use the StoredValues property to specify property names which cannot be assigned to the form session properties using the Object Inspector. It can be used for properties which cannot be represented as a singular value or do not have published visibility. Use the OnSaveProperties and OnRestoreProperties event handlers to store or restore (respectively) the values for these items in StoredValues.

The class can alo be used to save and restore properties for TFrame instances on a form, but it requires some additional coding. The RootNodePath must be specified to identify the path where the TFrame values are stored. In addition, the SessionProperties for the frame must be assigned in an overridden constructor and the Restore method must be called to reload the values. The Save method method also be called in na overridden Destructor for the frame.

A demonstration program is located in the examples/propstorage/ directory.

A tutorial for TXMLPropStorage is located on the Lazarus Wiki at:

https://wiki.lazarus.freepascal.org/TXMLPropStorage

Use TINIPropStorage or TJsonPropStorage components to save and restore session properties using either a .INI file or a JSON (JavaScript Object Notation) file.

## See also

TXMLPropStorage |  | Implements a class for XML storage of Form Session properties.
TFormPropertyStorage |  | TFormPropertyStorage - class for storage of a Form's properties.
TForm.SessionProperties |  | Delimited list of form and / or component properties saved to and restored from an external storage mechanism.
TINIPropStorage |  | Implements a class used to store session properties in an INI file.
TJSONPropStorage |  | Implements the final class for the JSON Form Session Properties storage.