The Tregistry object can be used in the 32-bit Delphi program to access the information in the registry file. First, create and release the Tregistry object 1. Create a Tregistry object. To operate the registry, create a Tregistry object: Aregistry: = Tregistry.create; 2. Release the Tregistry object. After the registry operation is completed, the Tregistry object should be released: Aregistry.Destroy. Second, when specifying the key operation registry to operate, first specify the primary key of the operation: first assign the property rootkey to specify the root key, then use the method OpenKey to specify the primary key name to operate. 1. Specify the root key (rootkey). The root key is the entry of the registry, and the category of the registry information is: HKEY-CLASS-ROOT: Store the entire system object class information, such as the ActiveX object registration, file association, etc. HKEY-CURRENT-User: Stores the current user's configuration information. The default value of the attribute rootkey. HKEY-LOCAL-MACHINE: Stores the software and hardware configuration information of the current system. Applications own information can be stored under this root key. HKEY-USERS: Store all user universal configuration information. It can also be HKEY-CURRENT-CONFIG, HKEY-DYN-DATA. 2. Specify the primary key to operate. Function OpenKey (const key: String; cancreate: boolean): boolean; key: Primary key name, is the part of the key name to remove the root key, such as Software. CANCREATE: Whether to create the primary key is allowed when the specified primary key name is not present, TRUE indicates allowed. The return value True indicates successful operation. 3. Turn off the current primary key. After reading or store information, the current primary key should be closed in time: Procedure Closekey. Third, read the information read series method from the registry read the specified information from the registry (string, binary, and hexadecimal) and convert to the specified type. AREAD series method. Function ReadString (const name: string): String; Read a string value, name is a string name. Function ReadInteger (const name: string): Integer; Read a integer value, name is an integer name. Function ReadbinaryData (const name: string; var buffer; buffer; reading binary value, Name is binary value name, buffer is the receiving buffer, buffsize is a buffer size, returning to the number of bytes actually read . Other methods include: ReadBool, Readcurrency, ReadDate, ReadDateTime, Readfloat, Readtime. 2. Read an example of information (display Windows version). Under HKEY-local-machine, there are three string values Version, VersionNumber, and SubversionNumber, which are used to record the current Windows version number.
{Uses include the unit in the Registry} procedure TForm1.Button1Click (Sender: TObject); var ARegistry: TRegistry; begin ARegistry: = TRegistry.Create; // create a TRegistry example with ARegistry do begin RootKey: = HKEY-LOCAL-MACHINE ; // Specify the root key to hkey-local-machine // Open the primary key Software if OpenKey ('Software', false) The begin Memo1.Lines.Add ('Windows version:' ReadString ('Version')); MEMO1. Lines.add ('Windows version number:' readstring ('versionnumber')); memo1.lines.add ('windows sub version number:' readstring ('SubversionNumber')); End; CloseKey; // Turn off primary key DESTROY ; // Release the memory END; END; 4, write the information WRITE series method to the registry to convert the information into the specified type, and write to the registry. 1.write series method. Procedure WriteString (const name, value: string); Write a string value, name is the name of the string, and Value is a string value. Procedure WriteInteger (const name: string; value: integer); Write an integer value. Procedure WriteBinaryData (const name: string; var buffer; buffs: integer); writing binary value, Name is the name of the binary value, buffer is a buffer containing binary values, buffs is buffer size. Other methods include: WriteBool, Writecurrency, WriteDate, WriteTime, Writefloat, WriteTime. 2. Write an example of information. The following program allows Delphi to start automatically with Windows. var ARegistry: TRegistry; begin ARegistry: = TRegistry.Create; // create a TRegistry example with ARegistry do begin RootKey: = HKEY-LOCAL-MACHINE; if OpenKey ( 'Software', True) then WriteString ( 'delphi', 'C : Files.exe '); CloseKey; Destroy; End; End; 5. Key value Maintenance In addition to reading, storage outside the registry, the program may also need to increase the primary key, remove the primary key, the primary key change, and the data value change. 1. Create a new primary key: Function CreateKey (const key: string): Boolean. Key is the primary key name, and the return value true indicates successful operation. 2. Remove the primary key: Function deleteKey (const key: string): Boolean. Key is the primary key name, and the return value true indicates successful operation. 3. Copy or move the primary key: Procedure MoveKey (Const OldName, NewName: String; Delete: Boolean).