Delphi common file processing and registry file usage examples
Foreword:
Registry provides us with methods to operate the registry. Here we use the method provided by TRegIniFile. TRegIniFile inherits from TRegistry. The method provided by TRegIniFile is similar to the method of operating Ini files mentioned earlier, which greatly simplifies our "mysterious" operation. Registry methods, the following are commonly used methods:
See examples
Create node
var reg:TRegIniFile; begin reg := TRegIniFile.Create; //Create instance reg.RootKey := HKey_Local_Machine; //Set root value if reg.OpenKey('SOFTWARE/MyReg',True) then //Open HKey_Local_Machine/SOFTWARE/ MyReg, if MyReg does not exist, begin is automatically created //Create the MySec item under HKey_Local_Machine/SOFTWARE/MyReg, and then create a string MyValue in MySec with the value China reg.WriteString('MySec','MyValue','China'); end; end;
Delete value
var reg:TRegIniFile; begin reg := TRegIniFile.Create; //Create instance reg.RootKey := HKey_Local_Machine; //Set root value if reg.OpenKey('SOFTWARE/MyReg/MySec',True) then begin //Delete the MyValue item under HKey_Local_Machine/SOFTWARE/MyReg/MySec reg.DeleteValue('MyValue'); end; end;
DeleteKey
var reg:TRegIniFile; begin reg := TRegIniFile.Create; //Create instance reg.RootKey := HKey_Local_Machine; //Set root value if reg.OpenKey('SOFTWARE/MyReg',True) then begin //Delete HKey_Local_Machine/SOFTWARE MySec under /MyReg reg.EraseSection('MySec'); end; end;
Reading the list of Keys and reading the list of values under the Key are similar to the operations of the INI file.
If you have any questions, please leave a message or go to the community of this site to communicate and discuss. Thank you for reading. I hope it can help everyone. Thank you for your support of this site!