19

以前の質問で、ユーザーが各コンポーネントの場所を個別に指定できる (コード部分と 2 つの HTML Web アプリケーションなど) 3 つのオプション コンポーネントを使用する方法を尋ねました。@Miral は、私が今実装したすばらしい答えをくれました:
3 つのユーザー定義の場所にある 3 つのコンポーネント

審美的な問題が少し残っています。私は常にCreateInputDirPageウィザードで , を作成してユーザーに尋ねています。の後に質問がありwpSelectComponentsます。

質問: コンポーネントが選択されていない場合、ページをスキップするにはどうすればよいですか? つまり、どうすればカスタム ページをスキップできますか?

と関係がある気がしますShouldSkipPage()。しかしPageID、カスタム ページの が何であるか、どのコンポーネントが選択されているかをテストする方法がわかりません。

function ShouldSkipPage(PageID: Integer): Boolean;

ウィザードはこのイベント関数を呼び出して、特定のページ (PageID で指定) を表示するかどうかを決定します。True を返すと、ページはスキップされます。False を返すと、ページが表示される場合があります。

私のスクリプトは以下に含まれています:

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

2 に答える 2

29

お察しのとおり、ShouldSkipPage条件付きでページをスキップするには、イベント ハンドラーを使用する必要があります。特定のコンポーネントが選択されているかどうかを確認するには、IsComponentSelected関数を使用します。最後に、カスタム ページの ID を取得するには、その を保存する必要がありますID。すべてをまとめると、次のサンプル スクリプトが得られます。

[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;
于 2012-12-17T20:31:36.253 に答える