【问题标题】:Disable controls based on components selection in Inno Setup根据 Inno Setup 中的组件选择禁用控件
【发布时间】:2018-03-12 18:33:08
【问题描述】:

我想根据所选组件禁用我的自定义页面 (VST2DirPage) 上的控件。我试过条件:

if IsComponentSelected('VST64') then  
begin
  VST2DirPage.Buttons[0].Enabled := False;
  VST2DirPage.PromptLabels[0].Enabled := False;
  VST2DirPage.Edits[0].Enabled := False;
end

但是这些元素似乎总是被禁用,所以看起来它没有获得正确的值来正常工作。脚本如下:

[Types]
Name: "full"; Description: "{code:FullInstall}";
Name: "custom"; Description: "{code:CustomInstall}"; Flags: iscustom

[Components]
Name: "VST64"; Description: "64-bit VST2"; Types: full; Check: Is64BitInstallMode
Name: "VST"; Description: "32-bit VST2"; Types: full; Check: Is64BitInstallMode
Name: "VST"; Description: "32-bit VST2"; Types: full; Check: not Is64BitInstallMode

[Code]
var VST2DirPage: TInputDirWizardPage;

procedure InitializeWizard;
begin
  VST2DirPage := CreateInputDirPage(wpSelectComponents,
    'Confirm VST2 Plugin Directory', '',
    'Select the folder in which setup should install the VST2 Plugin, then click Next.',
    False, '');

  VST2DirPage.Add('64-bit folder');
  VST2DirPage.Values[0] := ExpandConstant('{reg:HKLM\SOFTWARE\VST,VSTPluginsPath|{pf}\Steinberg\VSTPlugins}');
  VST2DirPage.Add('32-bit folder');
  VST2DirPage.Values[1] := ExpandConstant('{reg:HKLM\SOFTWARE\WOW6432NODE\VST,VSTPluginsPath|{pf32}\Steinberg\VSTPlugins}');

  if not Is64BitInstallMode then
  begin
    VST2DirPage.Buttons[0].Enabled := False;
    VST2DirPage.PromptLabels[0].Enabled := False;
    VST2DirPage.Edits[0].Enabled := False;
  end;
end;

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    InitializeWizard event function 甚至在安装程序显示之前就发生了。那时,您还不知道用户将选择哪些组件。

    只有当您知道选择了哪些组件时,您才需要更新控件的状态:

    • 离开“选择组件”页面时。
    • 或者在进入您的自定义页面时。

    这显示了后一种方法(使用CurPageChanged event function 实现):

    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = VST2DirPage.ID then
      begin
        VST2DirPage.Buttons[0].Enabled := not WizardIsComponentSelected('VST64');
        VST2DirPage.PromptLabels[0].Enabled := VST2DirPage.Buttons[0].Enabled;
        VST2DirPage.Edits[0].Enabled := VST2DirPage.Buttons[0].Enabled;
      end;
    end;
    

    请注意,上面的代码不仅禁用所选组件时禁用控件。如果用户返回“选择组件”页面并取消选择组件,它还会重新启用它们。


    另请参阅类似问题:
    Inno Setup - Change a task description label's color and have a line break。

    【讨论】:

      猜你喜欢
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多