Inno Setup:如果选择了另一个组件,如何自动选择组件?

时间:2017-11-22 09:28:48

标签: inno-setup

我只有在安装了特定组件的情况下才能安装文件。但我也允许自定义安装。因此,如果还检查了特定组件,则需要自动检查组件(反之亦然,如果未启用其他组件则禁用)。我知道我可以简单地将文件本身附加到特定组件,但我想向用户提供有关正在安装此先决条件的反馈。

那么,短版本:如何根据组件'B'的状态自动检查组件'A'?

1 个答案:

答案 0 :(得分:1)

检查B的简单实现,如果选中A:

[Components]
Name: "A"; Description: "A"
Name: "B"; Description: "B"

[Code]

const
  ItemA = 0;
  ItemB = 1;

var
  PrevItemAChecked: Boolean;
  TypesComboOnChangePrev: TNotifyEvent;

procedure ComponentsListCheckChanges;
begin
  if PrevItemAChecked <> WizardForm.ComponentsList.Checked[ItemA] then
  begin
    if WizardForm.ComponentsList.Checked[ItemA] then
      WizardForm.ComponentsList.Checked[ItemB] := True;

    PrevItemAChecked := WizardForm.ComponentsList.Checked[ItemA];
  end;
end;

procedure ComponentsListClickCheck(Sender: TObject);
begin
  ComponentsListCheckChanges;
end;

procedure TypesComboOnChange(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  TypesComboOnChangePrev(Sender);
  { And then check for changes }
  ComponentsListCheckChanges;
end;

procedure InitializeWizard();
begin
  WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;

  { The Inno Setup itself relies on the WizardForm.TypesCombo.OnChange, }
  { so we have to preserve its handler. }
  TypesComboOnChangePrev := WizardForm.TypesCombo.OnChange;
  WizardForm.TypesCombo.OnChange := @TypesComboOnChange;

  { Remember the initial state }
  { (by now the components are already selected according to }
  { the defaults or the previous installation) }
  PrevItemAChecked := WizardForm.ComponentsList.Checked[ItemA];
end;

以上内容基于Inno Setup ComponentsList OnClick event

您也可以使用与Inno Setup Uncheck a task when another task is checked类似的组件名称和描述,而不是使用索引。

相关问题