Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

pascalscript - Disable controls based on components selection in Inno Setup

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:HKLMSOFTWAREVST,VSTPluginsPath|{pf}SteinbergVSTPlugins}');
  VST2DirPage.Add('32-bit folder');
  VST2DirPage.Values[1] := ExpandConstant('{reg:HKLMSOFTWAREWOW6432NODEVST,VSTPluginsPath|{pf32}SteinbergVSTPlugins}');

  if not Is64BitInstallMode then
  begin
    VST2DirPage.Buttons[0].Enabled := False;
    VST2DirPage.PromptLabels[0].Enabled := False;
    VST2DirPage.Edits[0].Enabled := False;
  end;
end;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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.


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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...