如何根据 Inno Setup 中的设置类型跳过自定义页面

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

我正在使用服务器和客户端 installation/setup 类型构建我的设置。 如果用户选择服务器类型,我需要跳过或隐藏自定义页面。 服务器类型只有一个自定义页面 select SQL 实例和一个启动按钮 sqlcmd 安装 DB,而客户端安装只复制一些文件到程序目录。

这是我的自定义页面测试代码:

[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;

ShouldSkipPage 事件函数中,将 PageIDTWizardPage.ID of the custom page. And use WizardSetupType support function 进行比较以测试所选的设置类型。

var
  Page: TWizardPage;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;

  if Page.ID = PageID then
    Result := (WizardSetupType(False) <> 'server');
end;

很明显,您的自定义页面必须在 之后显示 "Select Components" 页面,而不是在:

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

或者,您可以处理自定义页面的 TWizardPage.OnShouldSkipPage