Inno Setup:选择组件的功能

时间:2014-11-20 12:36:06

标签: inno-setup

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

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

提前问候并致谢。

1 个答案:

答案 0 :(得分:0)

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

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

可以理解为:

  

跳过页面,如果" help"未选择组件并且" readme \ de"   组件也未被选中。在人类语言中它可以是,跳过   页面,如果没有"帮助"也不是" readme \ de"组件被选中。

您的代码可以简化为:

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语句中切换相同的标识符。编译器不应该允许你这样做但不幸的是,例如这编译:

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;

但只执行第一个开关值语句,因此您永远不会看到消息" Case switch 1.2"