代码:
 reg.rootKey:=HKEY_CLASSES_ROOT;
   if FlatCheckBox2.Checked=True then
      begin
        reg.OpenKey('lnkfile',true);
        if reg.ValueExists('IsShortCut')=true then
           reg.DeleteValue('IsShortCut');
      end
   else
      reg.OpenKey('lnkfile',true);
      reg.WriteString('IsShortCut','');
end;
      reg.CloseKey;
      reg.Free;
在上面代码中.键值可以新建但删不了.为什么呢? 

解决方案 »

  1.   

    reg.rootKey:=HKEY_CLASSES_ROOT定位到了该根上,可能是下面没有打开详细键值吧。
      

  2.   


     reg.rootKey:=HKEY_CLASSES_ROOT;
       if FlatCheckBox2.Checked=True then
          begin
            reg.OpenKey('lnkfile',false);
           // if reg.ValueExists('IsShortCut')=true then
               reg.DeleteValue('IsShortCut');
          end
       else
          reg.OpenKey('lnkfile',true);
          reg.WriteString('IsShortCut','');
    end;
          reg.CloseKey;
          reg.Free;
      

  3.   

    你自己删除之后马上又重新建立了一个,看上去当然删除不了了啊 reg.rootKey:=HKEY_CLASSES_ROOT;
       if FlatCheckBox2.Checked=True then
          begin
            reg.OpenKey('lnkfile',true);
            if reg.ValueExists('IsShortCut')=true then
               reg.DeleteValue('IsShortCut');
          end
       else
          begin  //这里用复合语句把, 只有FlatCheckBox2.Checked=True 才写键进去  
            reg.OpenKey('lnkfile',true);
            reg.WriteString('IsShortCut','');   
          end;
    end;
          reg.CloseKey;
          reg.Free;
      

  4.   

    Thank you niat97222(Freeman)你帮我解决了.大家都有分