Inno Setup: how to auto select a component if another component is selected?

后端 未结 1 1082
南笙
南笙 2020-12-17 07:31

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 spe

相关标签:
1条回答
  • 2020-12-17 07:48

    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.

    0 讨论(0)
提交回复
热议问题