为什么用KeyExists函数会出错呢(50分)

  • 主题发起人 主题发起人 zhb2002
  • 开始时间 开始时间
Z

zhb2002

Unregistered / Unconfirmed
GUEST, unregistred user!
验证注册表的某项存在,应用KeyExists函数,<br>却无论此项是否存在,总是得到False,<br>以下是代码<br>运行请修改const的 &nbsp;KEY 值<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls,Registry;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; public<br><br>&nbsp; end;<br>const<br>&nbsp; KEY = 'Software/Traffic/1.1.1';<br>&nbsp; ROOTKEY = HKEY_LOCAL_MACHINE;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; theRegistry: TRegistry;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>bool1:Boolean;<br>begin<br>&nbsp; theRegistry := TRegistry.Create;<br>&nbsp; theRegistry.RootKey := ROOTKEY;<br>&nbsp; theRegistry.OpenKey(KEY,False);<br><br>&nbsp; bool1:=theRegistry.KeyExists('KeepWeek');<br><br>&nbsp; theRegistry.Closekey;<br>&nbsp; theRegistry.Free;<br>end;<br>end.<br>
 
你的本意可能应该将KeyExists换成ValueExists
 
中午来试。做个记号。
 
<br>&nbsp; 换个函数看看。<br>&nbsp; ValueExists();
 
果然不行,关注!
 
To LeeChange:<br>哎,对呀,<br>KeyExists换成ValueExists就好了<br>那么前者是作何用。我看HELP,也是同一个意思!<br><br><br><br>
 
举个例子吧.<br>const<br>&nbsp; KEY = 'Software/Traffic';<br>&nbsp; ROOTKEY = HKEY_LOCAL_MACHINE;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; theRegistry: TRegistry;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>bool1:Boolean;<br>begin<br>&nbsp; theRegistry := TRegistry.Create;<br>&nbsp; theRegistry.RootKey := ROOTKEY;<br>&nbsp; theRegistry.OpenKey(KEY,False);<br><br>&nbsp; bool1:=theRegistry.KeyExists('1.1.1');<br><br>&nbsp; theRegistry.Closekey;<br>&nbsp; theRegistry.Free;<br>end;<br><br>返回就是True了,能理解了吧.<br>
 
不是吧???<br><br>我先问一句:你分清楚“KEY”和“VALUE”了吗?<br><br>用DELPHI操作注册表很容易的啊!!!
 
zhb2002:<br><br>去看我提供的原码? &nbsp;论坛上还专门 有个兄台问我这个问题!<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1242510<br><br>
 
谢谢各位,我确实把keyExists 和 ValueExists搞混了<br>早知有这么多在富翁相助,我应该早些来才是。<br>再次感谢
 

Similar threads

I
回复
0
查看
878
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部