【问题标题】:How to allow to only install specific components in InnoSetup?如何只允许在 InnoSetup 中安装特定组件?
【发布时间】:2012-04-23 15:26:35
【问题描述】:

所以问题是这样的: 我在这里问了一个问题:How to allow installation only to a specific folder?

我该如何修改它,例如,我有 3 个文件要安装,其中 2 个是可选的,只有在存在某个文件/文件夹时才可以安装。如果不满足条件,我想将在列表中选择它们的选项设为灰色?

提前谢谢你。 Zsolt

【问题讨论】:

  • 您好,选择灰色选项您的意思是在组件选择列表中禁用它们?
  • TLama:是的,这正是我的意思。但如果条件为真,我应该可以选择它们进行安装。

标签: conditional inno-setup


【解决方案1】:

我会尝试执行以下操作。它将访问组件列表项,通过它们的索引禁用和取消选中它们,从[Components] 部分的顺序中获取的从 0 开始的数字是多少。没有fixed 标志的项目(如本例)默认启用,因此您需要检查是否不满足条件。你也可以查看这篇文章的commented version

[Components]
Name: Component1; Description: Component 1
Name: Component2; Description: Component 2
Name: Component3; Description: Component 3

[code]
procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
    if not SomeCondition then
    begin
      WizardForm.ComponentsList.Checked[1] := False;
      WizardForm.ComponentsList.ItemEnabled[1] := False;
      WizardForm.ComponentsList.Checked[2] := False;
      WizardForm.ComponentsList.ItemEnabled[2] := False;
    end;
end;

上述解决方案至少有一个弱点。当您将ComponentsList.Sorted 设置为True 时,索引可能会从[Components] 部分的原始顺序打乱。如果你不
使用它,使用上面的代码可能就足够了,如果是,那就更复杂了。

没有简单的方法来获取组件名称(它在内部存储为每个项目的ItemObject 中的TSetupComponentEntry 对象),只有描述,所以这里有另一种方法可以做到这一点,不同之处在于正在按指定的描述搜索项目索引。

procedure CurPageChanged(CurPageID: Integer);
var
  Index: Integer;
begin
  if CurPageID = wpSelectComponents then
    if not SomeCondition then
    begin
      Index := WizardForm.ComponentsList.Items.IndexOf('Component 2');
      if Index <> -1 then
      begin
        WizardForm.ComponentsList.Checked[Index] := False;
        WizardForm.ComponentsList.ItemEnabled[Index] := False;
      end;
      Index := WizardForm.ComponentsList.Items.IndexOf('Component 3');
      if Index <> -1 then
      begin
        WizardForm.ComponentsList.Checked[Index] := False;
        WizardForm.ComponentsList.ItemEnabled[Index] := False;
      end;
    end;
end;

【讨论】:

  • +1 提到WizardForm.ComponentsList 财产,这让我的生活更轻松
猜你喜欢
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 2015-02-06
  • 1970-01-01
  • 2021-05-02
相关资源
最近更新 更多