Disable controls based on components selection in

2019-01-26 00:52发布

问题:

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;

回答1:

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.

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 IsComponentSelected('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.


See also a similar question:
Inno Setup - Change a task description label's color and have a line break.