根据Inno Setup中的组件选择禁用控件 [英] Disable controls based on components selection in Inno Setup
问题描述
我想基于所选组件在自定义页面(VST2DirPage
)上禁用控件.我已经尝试过这种情况:
I'd like to disable controls on my custom page (VST2DirPage
) based on selected components. I have tried the condition:
if IsComponentSelected('VST64') then
begin
VST2DirPage.Buttons[0].Enabled := False;
VST2DirPage.PromptLabels[0].Enabled := False;
VST2DirPage.Edits[0].Enabled := False;
end
但是元素似乎总是被禁用,因此看起来好像没有获得正确的值来正常工作.以下脚本:
But the elements seems to be always disabled, so it looks like it is not getting the correct values to work properly. Script below:
[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;
推荐答案
InitializeWizard
事件功能甚至在显示安装程序之前就已发生.到那时,您还不知道用户将选择哪些组件.
InitializeWizard
event function happens even before the installer is shown. At that point, you do not know yet, what components a user will select.
仅当您知道选择了哪些组件时,才必须更新控件的状态 :
You have to update a controls' state only when you know what components are selected:
- 退出选择组件"页面页面时.
- 或者在进入自定义页面时.
- Either when leaving the "Select Components" page.
- Or when entering your custom page.
这显示了后面的方法(使用 CurPageChanged
事件函数实现):
This shows the later approach (implemented using 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;
请注意,上面的代码不仅禁止控制,当组件被选中.如果用户返回到选择组件" 页面并取消选择该组件,它也会重新启用它们.
Note that the above code not only disables the controls, when the component is selected. It also re-enables them, if user returns back to "Select Components" page and unselects the component.
另请参阅类似的问题:
Inno设置-更改任务描述标签的颜色,并有换行符.
See also a similar question:
Inno Setup - Change a task description label's color and have a line break.
这篇关于根据Inno Setup中的组件选择禁用控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!