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.

我的脚本如下:

  1. [Components]
  2. Name: "Watson"; Description: "Watson Component"; Types: onlywatson full
  3. Name: "Toby"; Description: "Toby Component"; Types: onlytoby full
  4. Name: "Sherlock"; Description: "Sherlock Component"; Types: onlysherlock full
  5.  
  6. [Code]
  7. var
  8. TobyDirPage: TInputDirWizardPage;
  9. SherlockDirPage: TInputDirWizardPage;
  10.  
  11. procedure InitializeWizard;
  12. begin
  13. 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 +
  14. 'To continue,click Next. If you would like to select a different folder,click Browse.',False,'New Folder');
  15. { Add item (with an empty caption) }
  16. TobyDirPage.Add('');
  17. { Set initial value (optional) }
  18. TobyDirPage.Values[0] := ExpandConstant('c:\wwwroot\Toby');
  19.  
  20. 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 +
  21. 'To continue,'New Folder');
  22. { Add item (with an empty caption) }
  23. SherlockDirPage.Add('');
  24. { Set initial value (optional) }
  25. SherlockDirPage.Values[0] := ExpandConstant('c:\wwwroot\Sherlock');
  26. end;
  27.  
  28. function GetTobyDir(Param: String): String;
  29. begin
  30. { Return the selected TobyDir }
  31. Result := TobyDirPage.Values[0];
  32. end;
  33.  
  34. function GetSherlockDir(Param: String): String;
  35. begin
  36. { Return the selected TobyDir }
  37. Result := SherlockDirPage.Values[0];
  38. end;

解决方法

正如您正确地提到,您需要使用 ShouldSkipPage事件处理程序来有条件地跳过页面.要检查是否选择某个组件使用 IsComponentSelected功能,最后获取您需要存储其 ID自定义页面的ID.将所有组合放在一起可能会提供以下示例脚本:
  1. [Setup]
  2. AppName=My Program
  3. AppVersion=1.5
  4. DefaultDirName={pf}\My Program
  5. OutputDir=userdocs:Inno Setup Examples Output
  6.  
  7. [Components]
  8. Name: "help"; Description: "Help File";
  9.  
  10. [Code]
  11. var
  12. CustomPageID: Integer;
  13.  
  14. procedure InitializeWizard;
  15. var
  16. CustomPage: TInputDirWizardPage;
  17. begin
  18. CustomPage := CreateInputDirPage(wpSelectComponents,'Caption','Description','SubCaption','NewFolderName');
  19. CustomPage.Add('Input');
  20. { store your custom page ID to further use in the ShouldSkipPage event }
  21. CustomPageID := CustomPage.ID;
  22. end;
  23.  
  24. function ShouldSkipPage(PageID: Integer): Boolean;
  25. begin
  26. { initialize result to not skip any page (not necessary,but safer) }
  27. Result := False;
  28. { if the page that is asked to be skipped is your custom page,then... }
  29. if PageID = CustomPageID then
  30. { if the component is not selected,skip the page }
  31. Result := not IsComponentSelected('help');
  32. end;

猜你在找的Delphi相关文章