RAD Studio |  |

Using TRegistry
See Also
Collapse All

If you are writing a Windows-only application and are comfortable with the structure of the system Registry, you can use TRegistry. Unlike TRegistryIniFile, which uses the same properties and methods of other ini file components, the properties and methods of TRegistry correspond more directly to the structure of the system Registry. You can specify both the root key and subkey using TRegistry, while TRegistryIniFile uses HKEY_CURRENT_USER as the root key.

In addition to methods for opening, closing, saving, moving, copying, and deleting keys, TRegistry lets you specify the access level you want to use.

Note: TRegistry is not available for cross-platform programming.
The following example retrieves a value from a registry entry:
Copy Code

    function GetRegistryValue(KeyName: string): string;
    var
      Registry: TRegistry;
    begin
    Registry := TRegistry.Create(KEY_READ);
      try
        Registry.RootKey = HKEY_LOCAL_MACHINE;
    // False because we do not want to create it if it doesn't exist
        Registry.OpenKey(KeyName, False);
        Result := Registry.ReadString('VALUE1');
      finally
        Registry.Free;
      end;
    end;

Copy Code

    #include <Registry.hpp>
    AnsiString GetRegistryValue(AnsiString KeyName)
    {
    AnsiString S;
    TRegistry *Registry = new TRegistry(KEY_READ);
    try
    {
    Registry->RootKey = HKEY_LOCAL_MACHINE;
    // False because we do not want to create it if it doesn't exist
    Registry->OpenKey(KeyName,false);
    S = Registry->ReadString("VALUE1");
    }
    __finally
    {
    delete Registry;
    }
    return S;
    }

See Also

Using TRegistryIniFile

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!