【问题标题】:Skipping custom pages based on optional components in Inno Setup跳过基于 Inno Setup 中可选组件的自定义页面
【发布时间】:2012-12-04 23:37:16
【问题描述】:

在之前的问题中,我询问了如何拥有三个可选组件,用户还可以分别指定每个组件的位置(例如,一个代码部分和两个 HTML Web 应用程序)。 @Miral 给了我一个很好的答案,我现在已经实现了:
three components in three user defined locations

我还有一个小的审美问题。我总是在向导中创建并询问用户CreateInputDirPage。问题出现在wpSelectComponents 之后。

问题:如果未选择组件,我如何跳过页面。也就是说,如何跳过我的自定义页面?

我感觉它与ShouldSkipPage() 有关。但我不知道我的自定义页面的 PageID 是什么,以及如何测试以查看选择了哪些组件。

function ShouldSkipPage(PageID: Integer): Boolean;

向导调用此事件函数来确定是否应该显示特定页面(由 PageID 指定)。如果返回True,则页面将被跳过;如果返回 False,可能会显示页面。

我的脚本附在下面:

[Components]
Name: "Watson"; Description: "Watson Component"; Types: onlywatson full
Name: "Toby"; Description: "Toby Component"; Types: onlytoby full
Name: "Sherlock"; Description: "Sherlock Component"; Types: onlysherlock full

[Code]
var 
    TobyDirPage: TInputDirWizardPage;
    SherlockDirPage: TInputDirWizardPage;

procedure InitializeWizard;
begin
  TobyDirPage := CreateInputDirPage(wpSelectComponents,
    'Select Location for Toby Web Pages', 'Where should we store the sample Toby application files?',
    'The sample Toby stand-alone map application will be saved in the following folder.'#13#10#13#10 +
    'To continue, click Next. If you would like to select a different folder, click Browse.',
    False, 'New Folder');
  { Add item (with an empty caption) }
  TobyDirPage.Add('');
  { Set initial value (optional) }
  TobyDirPage.Values[0] := ExpandConstant('c:\wwwroot\Toby');
  
  SherlockDirPage := CreateInputDirPage(wpSelectComponents,
    'Select Location for Sherlock Web Pages', 'Where should we store the Sherlock Catalog Search Tool?',
    'Sherlock.html and it'#39 + 's associated files will be saved in the following folder.'#13#10#13#10 +
    'To continue, click Next. If you would like to select a different folder, click Browse.',
    False, 'New Folder');
  { Add item (with an empty caption) }
  SherlockDirPage.Add('');
  { Set initial value (optional) }
  SherlockDirPage.Values[0] := ExpandConstant('c:\wwwroot\Sherlock');
end;

function GetTobyDir(Param: String): String;
begin
  { Return the selected TobyDir }
  Result := TobyDirPage.Values[0];
end;

function GetSherlockDir(Param: String): String;
begin
  { Return the selected TobyDir }
  Result := SherlockDirPage.Values[0];
end;

【问题讨论】:

    标签: inno-setup


    【解决方案1】:

    正如您的正确预感,您需要使用ShouldSkipPage 事件处理程序来有条件地跳过页面。要检查是否选择了某个组件,请使用 IsComponentSelected 函数,最后,要获取自定义页面的 ID,您需要存储其 ID。将所有内容放在一起可能会为您提供以下示例脚本:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    OutputDir=userdocs:Inno Setup Examples Output
    
    [Components]
    Name: "help"; Description: "Help File";
    
    [Code]
    var
      CustomPageID: Integer;
    
    procedure InitializeWizard;
    var
      CustomPage: TInputDirWizardPage;
    begin
      CustomPage := CreateInputDirPage(wpSelectComponents, 'Caption', 
        'Description', 'SubCaption', False, 'NewFolderName');
      CustomPage.Add('Input');
      { store your custom page ID to further use in the ShouldSkipPage event }
      CustomPageID := CustomPage.ID;
    end;
    
    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
      { initialize result to not skip any page (not necessary, but safer) }
      Result := False;
      { if the page that is asked to be skipped is your custom page, then... }
      if PageID = CustomPageID then
        { if the component is not selected, skip the page }
        Result := not IsComponentSelected('help');
    end;
    

    【讨论】:

    • 我觉得是THE答案,不过今天一直很忙,想测试一下。但对我来说,它看起来很透彻,解释得很好。谢谢。
    • 不客气!如果您需要与此问题相关的任何帮助,请随时在此处发表评论;-)
    • 感谢您的回答。如果我选择不选中该组件,则页面确实没有按预期显示,但如果我首先选择组件,请查看自定义页面,然后返回组件选择并更改我的选择 - 取消选中该组件,自定义页面出现...有没有办法避免这种情况?
    • @one,这不应该发生。你能分享一个可以重现的简约脚本吗?
    • @TLama:他已经保存了向导页面对象,因此也不需要缓存它们的 ID。 ShouldSkipPage 中的检查将类似于 if (PageID = TobyDirPage.ID) then ... else if (PageID = SherlockDirPage.ID) then ...
    【解决方案2】:

    我的看法是使用 TWizardPageShouldSkipEvent,我只制作了一个案例和点脚本:

    [Code]
    var 
        TobyDirPage: TInputDirWizardPage;
    
    function SkipEvent (Sender: TWizardPage): Boolean;
    begin
        Result := not IsComponentSelected('Toby');
    end; 
    
    procedure InitializeWizard;
    begin
        TobyDirPage := CreateInputDirPage(wpSelectComponents, yadda yadda yadda
        TobyDirPage.OnShouldSkipPage := @SkipEvent;
    end;
    

    现在,OnShouldSkipPage 在按下 wpSelectComponents 上的 Next 之后以及在绘制 TobyDirPage 之前立即触发,由于您可以将该事件附加到页面本身,因此您无需摆弄 PageID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多