Skipping custom pages based on optional components in Inno Setup

前端 未结 2 1326
广开言路
广开言路 2020-12-05 14:44

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 HT

相关标签:
2条回答
  • 2020-12-05 15:37

    My take on this is to use the TWizardPageShouldSkipEvent, I've made only a case-and-point script:

    [Code]
    var 
        TobyDirPage: TInputDirWizardPage;
    
    function SkipEvent (Sender: TWizardPage): Boolean;
    begin
        Result := not IsComponentSelected('Toby');
    end; 
    
    procedure InitializeWizard;
    begin
        TobyDirPage := CreateInputDirPage(wpSelectComponents, yadda yadda yadda
        TobyDirPage.OnShouldSkipPage := @SkipEvent;
    end;
    

    Now, OnShouldSkipPage fires right after pressing Next on wpSelectComponents and before TobyDirPage gets painted and since you can attach that event to the page itself you don't need to fiddle with PageID's.

    0 讨论(0)
  • 2020-12-05 15:39

    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;
    
    0 讨论(0)
提交回复
热议问题