Charon
Charon

Reputation: 47

Disable Inno Setup Next button until user selects the radio button

I want to create an installer that has two versions of the software. I've implemented the radio button. But user can also click "Next" and the setup install nothing.

I want to disable the "Next" button until user select some of the options from the page.

[Code]
var
  UsagePage: TInputOptionWizardPage;

function IsProVersion(Mode: Integer): Boolean;
begin
  Result := (UsagePage.SelectedValueIndex = Mode);
end;

procedure InitializeWizard();
begin
  UsagePage :=
    CreateInputOptionPage(
      wpInfoBefore, 'Select Edition', 'Select Edition',
      'Select software edition you want to install on your computer.',
      True, False);
  UsagePage.Add('Free version');
  UsagePage.Add('Pro version (30 Days Trial)');
end;


[Files]
Source: "D:\software\free\*"; DestDir: "{app}"; \
    Flags: ignoreversion recursesubdirs createallsubdirs; Check: IsProVersion(0)
Source: "D:\software\pro\*"; DestDir: "{app}"; \
    Flags: ignoreversion recursesubdirs createallsubdirs; Check: IsProVersion(1)

Upvotes: 2

Views: 354

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202514

Use UsagePage.CheckListBox.OnClickCheck event to detect selection change and update the Next button state accordingly:

[Code]

var
  UsagePage: TInputOptionWizardPage;

procedure VerifyUsagePage(Sender: TObject);
var
  AnyChecked: Boolean;
  I: Integer;
begin
  AnyChecked := False;
  for I := 0 to UsagePage.CheckListBox.Items.Count - 1 do
  begin
    if UsagePage.CheckListBox.Checked[I] then
      AnyChecked := True;
  end;
  WizardForm.NextButton.Enabled := AnyChecked;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = UsagePage.ID then
  begin
    // Update the Next button state when entering the page
    VerifyUsagePage(nil);
  end;
end;

procedure InitializeWizard();
begin
  UsagePage :=
    CreateInputOptionPage(
      wpInfoBefore, 'Select Edition', 'Select Edition',
      'Select software edition you want to install on your computer.',
      True, False);
  UsagePage.Add('Free version');
  UsagePage.Add('Pro version (30 Days Trial)');
  // Update the Next button state on the selection change
  UsagePage.CheckListBox.OnClickCheck := @VerifyUsagePage;
end;

Though for selecting what to install, you better use built-in mechanisms of Inno Setup, like installations types and components.

Upvotes: 2

Related Questions