Search code examples
inno-setupback-buttonpascalscript

Inno Setup - Show MsgBox and click 'OK' go back to previous page


I have 'A' page TOutputMsgWizardPage and 'B' page TInputQueryWizardPage.

When I click B page's 'Next', show a MsgBox including 'OK' and 'Cancel' button. When I click 'OK', going back to 'A' page.

Could it happen?

Any tips on how I can achieve this?

Page sequence is: WelcomePage => OutputMsgPage => InputQueryPage => SelectDirPage


Solution

  • Use TWizardPage.OnNextButtonClick to handle "Next" button clicks.

    When handling the "Next" button, you can simulate a press on the "Back" button to go back to the previous page instead.

    [Code]
    
    var
      OutputMsgPage: TOutputMsgWizardPage;
      InputQueryPage: TInputQueryWizardPage;
    
    function InputQueryPageNextButtonClick(Sender: TWizardPage): Boolean;
    begin
      Result := True;
    
      if MsgBox('Go back?', mbConfirmation, MB_OKCANCEL) = IDOK then
      begin
        WizardForm.BackButton.OnClick(WizardForm.BackButton);
    
        Result := False;
      end;
    end;
    
    procedure InitializeWizard();
    begin
      OutputMsgPage :=
        CreateOutputMsgPage(wpWelcome, 'Output page', '', 'Output page');
    
      InputQueryPage :=
        CreateInputQueryPage(OutputMsgPage.ID, 'Input page', '', 'Input page');
      InputQueryPage.OnNextButtonClick := @InputQueryPageNextButtonClick;
    end;