Inno Setup: Function to select a component

2019-08-08 07:25发布

问题:

I have a small problem. I need that a page is displayed when you select one or two components. But the other is not work only with a single component seems to have an effect. I leave the code that I'm working.

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

A greeting and thanks in advance.

回答1:

If you need to write more complex conditions, use logical operators for that. In this case you wanted to use the and operator:

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

Which can be read as:

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.

Your code so can be simplified to this:

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;

One final note (and a possible cause of problems), beware of switching on the same identifier in case statements. Compiler should not allow you doing this but unfortunately does, e.g. this compiles:

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;

But only the first switch value statement executes, so you'll never see the message "Case switch 1.2".



标签: inno-setup