关于获得安装程序列表的问题~~(0分)

  • 主题发起人 主题发起人 flyso
  • 开始时间 开始时间
F

flyso

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大侠帮忙看看为什么运行出错
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,Registry;

type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
Cur='/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall';
var
reg :TRegistry;
List1 :TStringList;
List2 :TStringList;
i,n :integer;
begin
//创建临时变量
reg:=TRegistry.Create;
List1:=TStringList.Create;
List1:=TStringList.Create;
//载入子键
with Reg do
begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKey(Cur,false);
GetKeyNames(List1);
end;

for i:=0 to List1.Count-1 do
begin
reg.OpenKey(Cur+'/'+List1.Strings,false);
reg.GetValueNames(List2);
//显示安装程序以DisplayName排序
n:=List2.IndexOf('DisplayName');
if (n<>-1) and (List2.IndexOf('UninstallString')<>-1) then
begin
//显示已安装程序名称
Listbox1.Items.Add(reg.ReadString(List2.Strings[n]));
end;
end;
//释放对象
List1.Free;
List2.Free;
reg.CloseKey;
reg.Destroy;
end;
end.
 
出什么错,可不可以贴上来看看!
 
编译很正常
但单击按钮时就出错了
Access violation at address 00000246. Write of address 00429620.
 
//创建临时变量
reg:=TRegistry.Create;
List1:=TStringList.Create;
List1:=TStringList.Create; 这里要改成List2:=TStringList.Create;你太不仔细了
//载入子键
 
[:)]汗,原来是这里出的错啊,我还检查几次都没看见~
谢谢~~~
 
后退
顶部