inno-setup – 根据Inno Setup中的可选组件跳过自定义页面

前端之家收集整理的这篇文章主要介绍了inno-setup – 根据Inno Setup中的可选组件跳过自定义页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在先前的问题中,我询问如何使用三个可选组件,用户还可以单独指定每个组件的位置(例如代码部分和两个 HTML Web应用程序). @Miral给了我一个很好的答案,我现在已经实施了:
three components in three user defined locations

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

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

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

function ShouldSkipPage(PageID: Integer): Boolean;

The wizard calls this event function to determine whether or not a particular page (specified by PageID) should be shown at all. If you return True,the page will be skipped; if you return False,the page may be shown.

我的脚本如下:

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

解决方法

正如您正确地提到,您需要使用 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','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;
原文链接:/delphi/101575.html

猜你在找的Delphi相关文章