CRegistry Class Description


The CRegistry class manages saving and retrieving data using the Windows Registry. This is the same technique used by software applications to manage their configuration data and other settings. The CRegistry class uses a registry key name to access a Registry location where the data are stored. Individual data values are stored by a (name, value) pair under the key. You can create your own script keys or work with Mira's internal program keys (i.e., keys not created by a script) that control Mira dialogs and commands. Manipulating Mira's internal registry keys can be a powerful asset to scripting but must be done with care.

Keys are stored in the following registry section:

     HKEY_CURRENT_USER\Software\Mirametrics\Mira\Params

The registry section cannot be changed. For example a key named "My Key" would be stored at

     HKEY_CURRENT_USER\Software\Mirametrics\Mira\Params\My Key

Beneath the key are any number of named values have any of the following data types: integer, real, string, Boolean, or RGB. Values are accessed by name using one of the class Get() or Set() methods.

Note that saving script keys in the --\Params registry section allows access to Mira's internal keys while allowing the risk of colliding with an internal Mira key of the same name. To reduce the risk of accidental name collision, it is recommended that script key names begin with some prefix name, like "(Script)". Moreover, using a key name starting with a "(" character causes the key to be stored at the beginning of the --\Params section of the Windows Registry where you can easily find it when viewing the registry using the Windows Registry Editor.

Working with Registry Keys

Working with the CRegistry class is straightforward:

1.   Open an existing key or create a new key by passing a name in the new or Open method.

2.   Read values from the open key using one of the Get...() methods.

3.   Save values to the open key using one of the Set...() methods.

4.   Close the key when you are finished with it using Close or delete.

Note: To permanently delete a key from the system registry, use DeleteKey.

Methods

Construction and destruction may be done using either of two equivalent pairs of constructors and destructor name. Most MX Script classes, including CRegistry, use the new / delete pair to construct and destroy an instance of a CRegistry object. For this class, Open / Close methods are included simply as alternative names that relate to the notion of opening and closing a registry key.

Construction

Object = CRegistry:new( sName )

    or

Object = CRegistry:Open( sName )

Destruction

Object:delete()

    or

Object:Close()

Methods

Construction & Destruction

new

Opens a key by creating a new CRegistry object that is an instance of the CRegistry class. Same as Open.

Open

Opens a key by creating a new CRegistry object that is an instance of the CRegistry class. Same as new.

delete

Closes a key by deleting the CRegistry object. Same as Close.

Close

Closes a key by deleting the CRegistry object. Same as delete.

Operations

GetBool

Returns a Boolean (true or false) value

GetInt

Returns an integer value.

GetNum

Returns a numeric value (in general, a real number).

GetStr

Returns a string value

GetRgb

Returns an RGB string value.

GetWnd

Returns the handle of a GUI window.

 

 

SetBool

Sets a key to a Boolean (true or false) value.

SetInt

Sets a value to an integer number.

SetNum

Sets a value to a real number.

SetStr

Sets a value to a string.

SetRgb

Sets a value to an RGB string.

SetWnd

Sets a value to the handle of a GUI window.

 

 

DeleteKey

Deletes the key or one of its values from the registry.

Related Topics

Script Classes

Mira Data Types