How to disable Next button if no component is selected in Inno Setup?

时间:2016-05-17 11:16:46

标签: inno-setup pascalscript

I have three components and if the user select any component it will do installations. Now I want to disable the Next button if the user don't select any components.

I am trying if not IsComponentSelected('xxx'), but it is not working. Can anyone please help me??

1 个答案:

答案 0 :(得分:1)

在组件选择更改时,没有简单的方法来更新 Next 按钮状态。

更简单的方法是在单击下一步按钮时显示消息:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;

  if CurPageID = wpSelectComponents then
  begin
    if WizardSelectedComponents(False) = '' then
    begin
      MsgBox('No component selected', mbInformation, MB_OK);
      Result := False;
    end;
  end;
end;

如果您坚持禁用下一步按钮,请使用:

var
  TypesComboOnChangePrev: TNotifyEvent;

procedure ComponentsListCheckChanges;
begin
  WizardForm.NextButton.Enabled := (WizardSelectedComponents(False) <> '');
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;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
  begin
    ComponentsListCheckChanges;
  end;
end;

要了解为什么需要这么多代码才能完成这么小的任务,请参阅Inno Setup ComponentsList OnClick event