program RegEditingExample; //name of our proggy
uses
SysUtils, //SysUtils module declaration
Windows, //Windows module declaration
Registry, //Registry module declaration
Dialogs;
var //below of this word are declarations of variables
Reg : TRegistry; //our first declared variable "Reg" (TRegistry)
S : AnsiString; //declaration of variable "S" (AnsiString)
H : HKEY; //declaration of variable "H" (hkey)
begin //start of the code.
//creating the class
Reg := TRegistry.Create();
//RootKey [property]
//assigning HKEY_CURRENT_USER to property "RootKey".
Reg.RootKey := HKEY_CURRENT_USER;
//OpenKey [function]
//key : String -> key name
//CanCreate : Boolean -> if key isn't exist, function will create it.
//Function opens specified key.
//Return value is boolean.
Reg.OpenKey('SoftwareMicrosoft',False);
//CreateKey [function]
//Key : String -> Registry Key Name.
//Function creates new registry key.
//If the function succeeds return value is "True" else function returns "False".
Reg.CreateKey('Our_Reg_Key');
//KeyExists [function]
//Key : String -> Registry Key Name.
//This function checks if the key is exists.
//If key is exists then function returns 1 else function returns 0.
Reg.KeyExists('Windows');
//ValueExists [function]
//Name : String -> name of the reg. value
//Function checks if the value is already exists.
//If value is exists then function returns 1 else function returns 0.
Reg.ValueExists('lol2');
//MoveKey [procedure]
//OldName : String -> old registry key name
//NewName : String -> new name of the registry key
//Delete : Boolean -> if True the key with OldName will be deleted
//This procedure moves/copies specified registry key (and it's subkeys and values!).
Reg.MoveKey('Our_Reg_Key','Moved_Reg_Key',False);
//DeleteKey [function]
//Do you remember? Before we created 2 reg keys.
//Now, we delete they by "DeleteKey" function
//Key : String -> Name of the key (it will be deleted)
//If the function succeeds return value is "True" else function returns "False".
Reg.DeleteKey('Our_Reg_Key');
Reg.DeleteKey('Moved_Reg_Key');
//This property is holding the current path, for example: 'SoftwareMicrosoft'
//In this example current path is assigned to variable "S".
//To see the Path you can call "MessageBox" function
//For example:
//MessageBox(0,PChar('The current path is '+Reg.CurrentPath),'Info',MB_ICONINFORMATION);
S := Reg.CurrentPath;
//WinAPI Registry Functions
//Don't know what is Windows API?
//Let's look: http://en.wikipedia.org/wiki/WinAPI
//Now I try to describe some WINAPI Registry Functions
//RegOpenKey function
//This function opens specified registry key.
//hKey - handle to an open registry key
//lpSubKey - name of the subkey
//phkResult - pointer to a variable that receives handle to the opened key.
//If the function succeeds, the return value is 0 (ERROR_SUCCESS)
//If the function fails, the return value is nonzero (see WinError.h)
//Example:
RegOpenKey(HKEY_CURRENT_USER,'SoftwareMicrosoft',H);
//RegCloseKey function
//This function closes handle to the specified reg key.
//hkey - handle to open registry key (it will be closed)
//If the function succeeds, the return value is 0 (ERROR_SUCCESS)
//If the function fails, the return value is nonzero (see WinError.h)
//Example:
RegCloseKey(HKEY_CURRENT_USER);
//RegCreateKey function
//This function creates new reg key,
//but if key is already exists function opens it.
//hKey - a handle to registry key
//lpSubKey - subkey to create (or open)
//phkResult - pointer to a variable that receives handle to the created/opened reg key
//If the function succeeds, the return value is 0 (ERROR_SUCCESS)
//If the function fails, the return value is nonzero (see WinError.h)
//Example:
RegCreateKey(HKEY_CURRENT_USER,'!Windows Registry Own3d
',H);
//RegDeleteKey function
//This function deletes specified reg key
//hKey - a handle to registry key
//lpSubKey - subkey to delete
//If the function succeeds, the return value is 0 (ERROR_SUCCESS)
//If the function fails, the return value is nonzero (see WinError.h)
//Example:
RegDeleteKey(HKEY_CURRENT_USER,'!Windows Registry Own3d
');
//Dare for more!
end. //end of the code.
This entry was posted on Friday, March 30th, 2007 at 12:44 pm and is filed under Object Pascal. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.