inno setup使用IsComponentSelected函数来禁用或启用自定义页面项

时间:2018-04-11 15:23:36

标签: inno-setup

Components Selection Page

Custom DirPage where the items are diasbled/enabled based on Components Selection

我需要代码来执行上述操作。

+ = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + = + =

下面是我编写的示例代码。问题是,当我们取消选择component =>时,它才会起作用单击下一步(仍然启用目录项)=>单击返回=>再次单击下一步(现在它可以工作,即禁用dir项目)

即。它在第一次尝试时不会刷新

抱歉英语不好

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Types] 
Name: full; Description: Full Installation
Name: custom; Description: Custom Installation; Flags: iscustom

[Components]
Name: "crfl"; Description: "Core Files"; Types: full custom; Flags: fixed
Name: "vst"; Description: "VST"; Types: full
Name: "vst64"; Description: "VST64"; Types: full

[Code]
var
  CPage: TInputDirWizardPage;

procedure InitializeWizard;
begin
  CPage := CreateInputDirPage(wpSelectComponents,
    'Select Personal Data Location', 'Where should personal data files be stored?',
    'Personal data files will be stored 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');

  CPage.Add('VST');
  CPage.Add('VST64');

  CPage.Values[0] := ExpandConstant('{pf}\VST');
  CPage.Values[1] := ExpandConstant('{pf}\VST64');
end;

procedure CurPageChanged(PageID: Integer);
begin
  if PageID = wpSelectComponents then begin
    CPage.PromptLabels[0].Enabled := False;
    CPage.Edits[0].Enabled := False;
    CPage.Buttons[0].Enabled := False;

    CPage.PromptLabels[1].Enabled := False;
    CPage.Edits[1].Enabled := False;
    CPage.Buttons[1].Enabled := False;

    if IsComponentSelected('vst') then begin
      CPage.PromptLabels[0].Enabled := True;
      CPage.Edits[0].Enabled := True;
      CPage.Buttons[0].Enabled := True;
    end;

    if IsComponentSelected('vst64') then begin
      CPage.PromptLabels[1].Enabled := True;
      CPage.Edits[1].Enabled := True;
      CPage.Buttons[1].Enabled := True;
    end;
  end;
end;

1 个答案:

答案 0 :(得分:0)

应该是:

  if PageID = CPage.ID then

此外,代码可以简化为:

procedure CurPageChanged(PageID: Integer);
begin
  if PageID = CPage.ID then
  begin
    CPage.PromptLabels[0].Enabled := IsComponentSelected('vst');
    CPage.Edits[0].Enabled := CPage.PromptLabels[0].Enabled;
    CPage.Buttons[0].Enabled := CPage.PromptLabels[0].Enabled;

    CPage.PromptLabels[1].Enabled := IsComponentSelected('vst64');
    CPage.Edits[1].Enabled := CPage.PromptLabels[1].Enabled;
    CPage.Buttons[1].Enabled := CPage.PromptLabels[1].Enabled;
  end;
end;