Inno Setup: how to auto select a component if anot

2020-02-11 17:06发布

I've a file the must be installed only if a specific component is also installed. But I also allow custom install. So there is the need to auto-check the component if a specific component is also checked (and vice versa, disable if the other component is not enabled). I know I can simply attach the file itself to the specific component, but I want to provide to user the feedback about this prerequisite being installed.

So, short version: how to auto check component 'A' based to check status of component 'B' ?

标签: inno-setup
1条回答
Viruses.
2楼-- · 2020-02-11 17:55

A simple implementation for checking B, if A is checked:

[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;

The code requires Inno Setup 6 for WizardIsComponentSelected and WizardSelectComponents (for a version of the code without those functions, see the answer history)


The above is based on Inno Setup ComponentsList OnClick event.

查看更多
登录 后发表回答