问题描述
在前面的问题中,我问如何拥有三个可选组件,用户还可以在其中分别指定每个组件的位置(例如,一个代码部分和两个HTML Web应用程序). @Miral给了我一个很好的答案,现在我已经实现了:
三个用户定义位置中的三个组件
In a prior question I asked how to have three optional components, where the user could also specify the locations for each component separately (e.g. a code part and two HTML web applications). @Miral gave me a great answer which I have now implemented:
three components in three user defined locations
我还有一个小的美学问题.我总是在向导中创建并要求用户输入CreateInputDirPage
.问题出现在wpSelectComponents
之后.
I have a small esthetic issue remaining. I am always creating and asking the user for a CreateInputDirPage
, in the wizard. The question comes after the wpSelectComponents
.
问题:如果未选择组件,如何跳过页面.也就是说,如何跳过自定义页面?
Question: How do I skip the page if the component was not selected. That is, how do I skip my custom page?
我觉得这与ShouldSkipPage()
有关.但是我不知道自定义页面的PageID
是什么,以及如何测试以查看选择了哪些组件.
I have a feeling it has to do with ShouldSkipPage()
. But I have no idea what the PageID
for my custom page is, and how to test to see what components were selected.
该向导调用此事件函数来确定是否应完全显示特定页面(由PageID指定).如果返回True,则页面将被跳过;如果返回False,则可能会显示该页面.
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, 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;
推荐答案
正确地选择前,您需要使用 ShouldSkipPage
事件处理程序有条件地跳过页面.要检查是否选择了某个组件,请使用 IsComponentSelected
函数,最后获取ID您的自定义页面需要存储其 ID
.将所有内容放在一起可能会为您提供以下示例脚本:
As you correctly forefelt, you need to use the ShouldSkipPage
event handler to conditionally skip the page. To check if a certain component is selected use the IsComponentSelected
function and finally, to get ID of your custom page you need to store its ID
. Putting all together might give you the following example script:
[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;
这篇关于根据Inno Setup中的可选组件跳过自定义页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!