操作注册表

 

思路如下:

 

1. 先引入Tregistry所在单元:registry;

 

2. 创建Tregistry的对象reg;

 

3. 给对象的属性赋值Reg.RootKey:=HKEY_CURRENT_USER;

4. OpenKey打开某个节点;

 

5. 读取值 Reg.ReadString(keyvalue);


//讀註冊表
function ReadReg(keyvalue:String;RegTag:Boolean):String;
var
  reg:Tregistry;
begin
  Reg:=Tregistry.Create;
  Result:='';
  try
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\maxsoft\ZJYT',False) then
    begin
      Result:=Reg.ReadString(keyvalue);
    end else //第一次運行寫註冊表
      Result:='';
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

 

 

function writeReg(KeyValue,WritedStr:string;RegTag:Boolean):Boolean;
var
  reg:Tregistry;
begin
//  if not Assigned(reg) then
  Reg:=Tregistry.Create;
  try
    Reg.RootKey:=HKEY_CURRENT_USER;
      if Reg.OpenKey('\Software\maxsoft\ZJYT',True) then
        Reg.WriteString(KeyValue,WritedStr);
    Reg.CloseKey;
    Result:=True;
  finally
    Reg.Free;
  end;

end;

你可能感兴趣的:(注册表)