【发布时间】:2013-05-27 15:30:30
【问题描述】:
我有以下代码尝试使用 JclIDEUtils 检测 Delphi 安装。为了测试它,我设置了两个虚拟机,都运行 Win 7,在两个系统中我都安装了 Delphi XE3,但在 VM n1 中我也安装了 Jcl,在 VM n2 中我没有。 好吧,在 n1 中,我的小程序工作正常,找到了 Delphi XE3,在 n2 中却没有! 我尝试在两个 VM 中远程调试程序,但我唯一理解的一件事是,如果未安装 Jcl,实例化 TJclBorRADToolInstallations 类的对象将保持为空。
这是我在表单的 OnShow 事件中的代码:
procedure TForm1.FormShow(Sender: TObject);
var
I, X: Integer;
TN, SubTn: TTreeNode;
IconIndex: Integer;
begin
FDelphiInstallations := TJclBorRADToolInstallations.Create;
for I := 0 to FDelphiInstallations.Count - 1 do
begin
IconIndex := ilDelphiIcons.AddIcon(GetSmallIcon(FDelphiInstallations[I].IdeExeFileName));
TN := tvDisplay.Items.AddChild(nil, FDelphiInstallations[I].Name);
TN.ImageIndex := ilDelphiIcons.Count - 1;
TN.SelectedIndex := ilDelphiIcons.Count - 1;
with tvDisplay.Items do
begin
SubTn := AddChild(TN, 'Description: ' + FDelphiInstallations[I].Description);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Root directory: ' + FDelphiInstallations[I].RootDir);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Projects directory: '+ FDelphiInstallations[i].DefaultProjectsDir);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Common Projects directory: '+ FDelphiInstallations[i].CommonProjectsDir);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Executable File name: '+ FDelphiInstallations[i].IdeExeFileName);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Build number: '+ FDelphiInstallations[i].IdeExeBuildNumber);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'VersionNumberStr='+ FDelphiInstallations[i].VersionNumberStr);
SubTn.ImageIndex := 0;
SubTn := AddChild(TN, 'Registry key='+ FDelphiInstallations[i].ConfigDataLocation);
SubTn.ImageIndex := 0;
for X := 0 to FDelphiInstallations[i].IdePackages.Count - 1 do
begin
SubTn := AddChild(TN, 'Description: ' + FDelphiInstallations[I].IdePackages.PackageFileNames[X]);
SubTn.ImageIndex := 0;
end;
end;
end;
end;
有人知道这个问题吗?
提前感谢您的任何建议。
【问题讨论】:
-
如果你查看源代码,
TJclBorRADToolInstallations.Create;只是创建了一个内部TObjectList并调用ReadInstallations,它只是尝试遍历可能的注册表项以查看 Delphi、C++Builder , 或已安装 RAD Studio。它不可能失败并返回nil;它可能找不到任何安装,但仍会返回该对象的实例。FDelphiInstallations.Count可以为零,这将阻止您的循环执行。您是否查看过出现故障的机器上的注册表本身(使用 RegEdit)? -
另外,当您进行安装时,您是否以管理员身份(开始安装时右键单击并选择
Run as administrator)在问题系统上进行安装?您是为特定用户安装的,还是为机器的所有用户安装的? -
感谢 Ken 的帮助。解决方案非常简单而且有点愚蠢:我必须运行一次 Delphi 才能让 JclIDEUtils 检测到该安装,即使我不明白为什么这会影响 Delphi 检测...