TRegistryPersist

TRegistryPersist provides an easy way to persist property values in the system registry.

Hierarchy:

TObject
TComponent

Properties:

Methods:

Using TRegistryPersist:

There are 6 basic steps to using a TRegistryPersist component:

  1. Drop the component on a form.
  2. Set the Root property.
  3. Set the Key property. The dialog only displays the registry from the key specified by Root down, but you may type any string into the key property as well.
  4. Select the properties to be persisted. This can be done either through the Properties property or through the component editor (double clicking on the component). If you need to set specific value names in the registry, you must do this through the Properties property.
  5. Set AutoLoad to true if you want the values loaded after the form loads.
  6. Save the values of the properties to the registry by using the Save procedure where appropriate.

TRegistryPersist works well for creating properties/preferences dialogs, since it allows you to store the last state of the dialog directly to the registry.


TRegistryPersist.AutoLoad

property AutoLoad: Boolean;

Read/write

AutoLoad determines whether the TRegistryPersist component automatically loads the properties specified in the Properties property with values from the system registry.


TRegistryPersist.Key

property Key: String;

Read/write

Key specifies the subkey of the root specified by Root that will be used for persisting the property values. This property does not have to be an immediate subkey of the root key, i.e. it may contain backslashes. Editing the property from the Object Inspector will bring up a dialog that can be used to specify the subkey. This dialog can also be used to add or remove keys from the registry.


TRegistryPersist.Properties

property Properties: TPropertyPersists;

Read/write

Properties is a collection of TPropertyPersist objects, each of which specifies one property to be persisted in the registry.


TRegistryPersist.Root

property Root: HKEY;

Read/write

Root specifies the starting key in the registry for the Key property. Any open key can be used, as well as the standard keys.


TRegistryPersist.Load

procedure Load;

Loads the values of the specified properties from the registry.


TRegistryPersist.Save

procedure Save;

Saves the values of the specified properties to the registry.


TPropertyPersists

TPropertyPersists is a collection of TPropertyPersist items.

Hierarchy:

TObject
TPersistent
TCollection

Properties:

Methods:


TPropertyPersists.Items

property Items[Index: Integer]: TPropertyPersist;

Read only

Items provides access to the elements of the collection.


TPropertyPersists.Owner

property Owner: TRegistryPersist;

Read only

Owner provides access to the owning instance of TRegistryPersist.


TPropertyPersists.Add

function Add: TPropertyPersist;

Add a new TPropertyPersist item to the end of the collection.


TPropertyPersists.FindItemID

function FindItemID(ID: Integer): TPropertyPersist;

Find a TPropertyPersist item by its unique ID. See also TCollection.FindItemID.


TPropertyPersists.Insert

function Insert(Index: Integer): TPropertyPersist;

Insert a new TPropertyPersists item at the specified location.


TPropertyPersist

A TPropertyPersist instance specfies the persistence attributes for one property.

Hierarchy:

TObject
TPersistent
TCollectionItem

Properties:


TPropertyPersist.Component

property Component: TComponent;

Read/write

Component specifies the component from which the property value will be read or to which the property value will be written.


TPropertyPersists.PropName

property PropName: String;

Read/write

PropName specifies the name of the property to be persisted. Only properties with the following types can be persisted:

All other types fail silently on save and load.


TPropertyPersist.ValueName

property ValueName: String

Read/write

ValueName indicates the name of the registry value that hold the persistent value of the property. By default, ValueName is of the form ComponentName.PropertyName. Unless explicitly specified, ValueName will change whenever Component or PropName changes.