我写了一个读取注册表键值的程序,可以运行,但一按“读取”键,就出现这个了:
Access vio lation at address 00425817 in module'run.exe'.Read of address 00000000
按确定就没了,程序依然运行,再按读取,又是这样的!!
为什么啊?unit biao_run;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst,Registry;type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count1,count2:integer;
reg:TRegistry;
Value1:Tstringlist;
Value2:Tstringlist;
implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
checklistbox1.Clear;
reg:=TRegistry.Create;
reg.Rootkey:=HKEY_LOCAL_MACHINE;//设置这个对象的根键为H _L_M
If reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false) then
begin
reg.GetValueNames(Value1);
count1:=Value1.Count
end;
for i:=0 to Value1.Count-1 do
begin
checklistbox1.Items.Add(Value1[i]+' '+reg.ReadString(Value1.Strings[i]))
end;
reg.RootKey:=HKEY_CURRENT_USER; //重新定义Myreg的根键为H_C_U
If reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',false) Then
begin
reg.GetValueNames(Value2);
count2:=Value2.Count;
end;
for i:=0 to Value2.Count-1 do
begin
checklistbox1.Items.Append(Value2[i]+' '+reg.ReadString(Value2.Strings[i]));
end;
reg.CloseKey;
reg.Free; end;end.这是代码啊,帮忙啊!
Access vio lation at address 00425817 in module'run.exe'.Read of address 00000000
按确定就没了,程序依然运行,再按读取,又是这样的!!
为什么啊?unit biao_run;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst,Registry;type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
count1,count2:integer;
reg:TRegistry;
Value1:Tstringlist;
Value2:Tstringlist;
implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
checklistbox1.Clear;
reg:=TRegistry.Create;
reg.Rootkey:=HKEY_LOCAL_MACHINE;//设置这个对象的根键为H _L_M
If reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false) then
begin
reg.GetValueNames(Value1);
count1:=Value1.Count
end;
for i:=0 to Value1.Count-1 do
begin
checklistbox1.Items.Add(Value1[i]+' '+reg.ReadString(Value1.Strings[i]))
end;
reg.RootKey:=HKEY_CURRENT_USER; //重新定义Myreg的根键为H_C_U
If reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',false) Then
begin
reg.GetValueNames(Value2);
count2:=Value2.Count;
end;
for i:=0 to Value2.Count-1 do
begin
checklistbox1.Items.Append(Value2[i]+' '+reg.ReadString(Value2.Strings[i]));
end;
reg.CloseKey;
reg.Free; end;end.这是代码啊,帮忙啊!
其中 count1:=Value1.Count 加不加分号都是一样。
begin
reg.GetValueNames(Value1);
count1:=Value1.Count
end;
Value2:Tstringlist;
这两个对象没有Create就用了
var i:integer;
begin
value1 := TStringList.Create;
value2 := TStringList.Create;//这里是你Button1Click原先的代码.... value1.Free;
value2.Free;
end;