inno-setuppascalscript

How to skip custom page based on setup type in Inno Setup


I'm building my setup with server and client installation/setup types. I need to skip or hide a custom page if user choose server type. Server type only have a custom page to select SQL instance and a button to launch sqlcmd to install DB, while client installation only copy some files to program directory.

This is my test code with custom page:

[Types]
Name: "Server"; Description: "Server"
Name: "Client"; Description: "Client"

[Components]
Name: "Dictation"; Description: "Dictation"; Types: Client
Name: "DigitalSign"; Description: "Digital Sign"; Types: Client

[Tasks]
Name: "Voisis"; Description: "Voisis"; Components: Dictation
Name: "Recomed"; Description: "Recomed"; Components: Dictation
[Code]

var
   Page: TWizardPage;
   Panel: TPanel;
   Edit0,Edit1,Edit2,Edit3: TNewEdit;
   StaticText0, StaticText1,StaticText2,StaticText3: TNewStaticText;

procedure InitializeWizard;
begin
    // Create the pages

    Page :=
      CreateCustomPage(wpInfoBefore, 'Personal Information', 'Who are you?');
    
    Edit0 := TNewEdit.Create(Page);
    Edit0.Top := ScaleY(16);
    Edit0.Width := Page.SurfaceWidth div 3 - ScaleX(8);
    Edit0.Text := 'localhost\WISE';
    Edit0.Parent := Page.Surface;

    Edit1 := TNewEdit.Create(Page);
    Edit1.Top := ScaleY(64);
    Edit1.Width := Page.SurfaceWidth div 3 - ScaleX(8);
    Edit1.Text := 'sa';
    Edit1.Parent := Page.Surface;

    Edit2 := TNewEdit.Create(Page);
    Edit2.Top := ScaleY(112);
    Edit2.Width := Page.SurfaceWidth div 3 - ScaleX(8);
    Edit2.Text := 'Password';
    Edit2.Parent := Page.Surface;

    Edit3 := TNewEdit.Create(Page);
    Edit3.Top := ScaleY(160);
    Edit3.Width := Page.SurfaceWidth div 3 - ScaleX(8);
    Edit3.Text := 'TNewEdit';
    Edit3.Parent := Page.Surface;

    StaticText0 := TNewStaticText.Create(Page);
    Statictext0.Top := ScaleY(2);
    StaticText0.Caption := 'Istanza';
    StaticText0.AutoSize := True;
    StaticText0.Parent := Page.Surface;

    StaticText1 := TNewStaticText.Create(Page);
    Statictext1.Top := ScaleY(50);
    StaticText1.Caption := 'User';
    StaticText1.AutoSize := True;
    StaticText1.Parent := Page.Surface;

    StaticText2 := TNewStaticText.Create(Page);
    Statictext2.Top := ScaleY(98);
    StaticText2.Caption := 'Password';
    StaticText2.AutoSize := True;
    StaticText2.Parent := Page.Surface;

    StaticText3 := TNewStaticText.Create(Page);
    Statictext3.Top := ScaleY(146);
    StaticText3.Caption := 'bho';
    StaticText3.AutoSize := True;
    StaticText3.Parent := Page.Surface;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
    Result := False;
  
    if PageID = PageID then
        Result := not IsComponentSelected('Server');
end;

Solution

  • In ShouldSkipPage event function, compare the PageID against the TWizardPage.ID of the custom page. And use WizardSetupType support function to test the selected setup type.

    var
      Page: TWizardPage;
    
    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
      Result := False;
    
      if Page.ID = PageID then
        Result := (WizardSetupType(False) <> 'server');
    end;
    

    And obviously, your custom page must show after the "Select Components" page, not before:

    Page := CreateCustomPage(wpSelectComponents, ...);
    

    Alternatively, you can handle TWizardPage.OnShouldSkipPage of the custom page.

    For an example, see Skip Inno Setup custom page, unless specific radio button is selected on previous page.