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

笑着哭i 提交于 2019-12-06 06:06:37
Martin Prikryl

There's no easy way to update the Next button state on component selection change.

A way easier is to display a message when the Next button is clicked:

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;

If you insist on disabling the Next button, use this:

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;

To understand why you need so much code for such a little task, see Inno Setup ComponentsList OnClick event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!