Inno Setup:选择组件的功能

Inno Setup: Function to select a component

我有一个小问题。 选择一个或两个组件时,我需要显示一个页面。 但是另一个不能只用一个组件工作似乎有效果。 我留下我正在工作的代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[Setup]
AppName=My Program
AppVerName=My Program v.1.2
DefaultDirName={pf}\\My Program

[Types]
Name: full; Description: Full installation
Name: compact; Description: Compact installation
Name: custom; Description: Custom installation; Flags: iscustom

[Components]
Name: program; Description: Program Files; Types: full compact custom; Flags: fixed
Name: help; Description: Help File; Types: full
Name: readme; Description: Readme File; Types: full
Name: readme\\en; Description: English; Flags: exclusive
Name: readme\\de; Description: German; Flags: exclusive

[Code]
var
  Page1: TWizardPage;

Procedure InitializeWizard();
begin
  Page1:= CreateCustomPage(wpSelectComponents, 'Custom wizard page 1', 'TButton');
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Case PageID of
    Page1.ID: Result:= not IsComponentSelected('help');
    Page1.ID: Result:= not IsComponentSelected('readme\\de'); //  It does not work
  end;
end;

预先致以问候和感谢。


如果您需要编写更复杂的条件,请使用逻辑运算符。 在这种情况下,您想使用and运算符:

1
Result := not IsComponentSelected('help') and not IsComponentSelected('readme\\de');

可以理解为:

Skip page if"help" component is not selected and"readme\\de"
component is not selected as well. In human language it could be, skip
page if neither"help" nor"readme\\de" component is selected.

您的代码可以简化为:

1
2
3
4
5
6
7
function ShouldSkipPage(PageID: Integer): Boolean;
begin
  // skip the page if it's our custom page and neither"help" nor"readme\\de"
  // component is selected, do not skip otherwise
  Result := (PageID = Page1.ID) and (not IsComponentSelected('help') and
    not IsComponentSelected('readme\\de'));
end;

最后一点(以及可能的问题原因)请注意,不要在case语句中打开相同的标识符。 编译器不应该允许您这样做,但不幸的是,例如 编译:

1
2
3
4
5
6
7
8
9
var
  I: Integer;
begin
  I := 1;
  case I of
    1: MsgBox('Case switch 1.1', mbInformation, MB_OK);
    1: MsgBox('Case switch 1.2', mbInformation, MB_OK);
  end;
end;

但是仅执行第一个switch值语句,因此您将永远不会看到消息" Case switch 1.2"。