19

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

我还有一个小的审美问题。我总是CreateInputDirPage在向导中创建并要求用户提供 , 。问题出现在wpSelectComponents.

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

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

函数 ShouldSkipPage(PageID: Integer): 布尔值;

向导调用此事件函数来确定是否应该显示特定页面(由 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;
4

2 回答 2

29

正如您正确地预感到的那样,您需要使用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;
于 2012-12-17T20:31:36.253 回答
6

我对此的看法是使用 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在按下 Next 之后立即触发,然后在绘制wpSelectComponents之前触发,TobyDirPage并且由于您可以将该事件附加到页面本身,因此您不需要摆弄 PageID。

于 2017-04-06T19:19:06.560 回答