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.
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.