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

rea*_*ebo 4 inno-setup

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

那么,简短的版本:如何自动检查组件“A”以检查组件“B”的状态?

Mar*_*ryl 5

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

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

[Code]

var
  PrevItemAChecked: Boolean;
  TypesComboOnChangePrev: TNotifyEvent;
  ComponentsListClickCheckPrev: TNotifyEvent;

procedure ComponentsListCheckChanges;
begin
  if PrevItemAChecked <> WizardIsComponentSelected('A') then
  begin
    if WizardIsComponentSelected('A') then
      WizardSelectComponents('B');

    PrevItemAChecked := WizardIsComponentSelected('A');
  end;
end;

procedure ComponentsListClickCheck(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  ComponentsListClickCheckPrev(Sender);
  { And then check for changes }
  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
  { The Inno Setup itself relies on the TypesCombo.OnChange and OnClickCheck. }
  { so we have to preserve their  handlers. }

  ComponentsListClickCheckPrev := WizardForm.ComponentsList.OnClickCheck;
  WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;

  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 := WizardIsComponentSelected('A');
end;
Run Code Online (Sandbox Code Playgroud)

该代码需要 Inno Setup 6WizardIsComponentSelectedWizardSelectComponents(对于没有这些功能的代码版本,请参阅答案历史记录)


以上是基于Inno Setup ComponentsList OnClick事件