CRegistry:Open


The Open method opens an existing key or creates a new registry key. It also constructs a new instance of a CRegistry object. After creating the new key, you can use the Get() and Set() methods to access its values. This is the same as the new method. If the named key exists, it is opened. If the key does not exist, it is created.

Syntax

R = CRegistry:Open( sKeyName )

R = CRegistry:Open( CRegistry2 )

where

    sKeyName is the name of a registry key to be opened.

    CRegistry2 is an existing CRegistry object which is opened by the new CRegistry object.

    R is the new CRegistry object returned.. On failure, nil is returned.

  

Two overloads are provided for this method. They either open a registry key or create separate access to the key of an existing CRegistry object. You must provide a key name as a parameter. If the named key exists, it is opened. If the key does not exist, it is created. A new key will not be saved to the Registry unless you use one of the Set() methods. The new method is equivalent to the new method, so you can use either the new / delete pair or the Open / Close pair to open and close the key.

Example

The following script opens a key and retrieves the "radius" value. If the radius value does not exist in the Registry, the default value of 5.2 is returned.

 

R = CRegistry:Open( "(Script) Test" )

-- open registry key "(Script) Test"

r = R:GetNum("radius", 5.2 )

-- fetch the "radius" value, default to 5.2

Printf("Rad= %lg", r )

-- result: Rad= 15.125 (already exists)

R:Close()

-- close access to the key

Related Topics

new

Close

DeleteKey

CRegistry class