Z
zhb2002
Unregistered / Unconfirmed
GUEST, unregistred user!
验证注册表的某项存在,应用KeyExists函数,<br>却无论此项是否存在,总是得到False,<br>以下是代码<br>运行请修改const的 KEY 值<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls,Registry;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> private<br> public<br><br> end;<br>const<br> KEY = 'Software/Traffic/1.1.1';<br> ROOTKEY = HKEY_LOCAL_MACHINE;<br><br>var<br> Form1: TForm1;<br> theRegistry: TRegistry;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>bool1:Boolean;<br>begin<br> theRegistry := TRegistry.Create;<br> theRegistry.RootKey := ROOTKEY;<br> theRegistry.OpenKey(KEY,False);<br><br> bool1:=theRegistry.KeyExists('KeepWeek');<br><br> theRegistry.Closekey;<br> theRegistry.Free;<br>end;<br>end.<br>