关于注册表:如何实现程序打开时没有键值名就生成一个并给值;而有时即读取其值?以下代码只实现得了前者。
reg:=tregistry.Create;
  reg.rootkey:=HKEY_LOCAL_MACHINE;
  if reg.openkey('\SoftWare\Microsoft\Windows\CurrentVersion\Run',true) then
  begin
    reg.WriteString('DiskNo',edit1.Text);
    reg.CloseKey;
    showmessage('registry sucess');
  end;
  reg.Free;
多谢先。

解决方案 »

  1.   

    参考这两个方法~~
      TRegistry::KeyExists();
      TRegistry::ValueExists();
      

  2.   

    if reg.valueExists('')=true then
      lines.Text:=regi.readstring()
      

  3.   

    procedure Tfrm_RFRead.SetAutoRun;
    var
      RegF:TRegistry;
    begin
      RegF := TRegistry.Create;
      RegF.RootKey := HKEY_LOCAL_MACHINE;
      RegF.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True);
      if not RegF.ValueExists('test') then
        RegF.WriteString('test',ParamStr(0)); //用Paramstr(0)返回当前执行程序的路径
      RegF.CloseKey;
      RegF.Free;
    end;