Daniel Paczuski Bak
Daniel Paczuski Bak

Reputation: 4088

Inno Setup: add fields to InputQueryPage depending on components selected

I have an input query page, which asks the user for ports depending on what components are selected.

procedure InitializeWizard;
begin
  { Create the page }
  ConfigPage :=
    CreateInputQueryPage(
      wpSelectComponents, 'User input', 'User input',
      'Please specify the following information, then click Next.');
  { Add items (False means it's not a password edit) }
  if IsComponentSelected('broker') then
  begin
    ConfigPage.Add('MQTT Broker port:', False);
    { Set initial values (optional) }
    ConfigPage.Values[0] := ExpandConstant('1883');
   end;
end;

The issue I am finding here is that InitializeWizard is always called prior to component selection, so IsComponentSelected('broker') is always called.

Is there any way around this? How can I achieve this?

Upvotes: 1

Views: 416

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202642

It's not easy. For a really generic solution, you would have to create the custom page only when leaving the components selection page (e.g. in NextButtonClick with CurPageID equal wpSelectComponents). That's doable, but Inno Setup allows user to go back to the components page. When the user does that, you would have to remove the custom page, re-creating it later. But you would lose the data the user might have entered on the custom page. So you would have to persist the data somehow. All that is doable, but lot of work.


If it is about few input boxes only, consider instead disabling the boxes that are not relevant for the current components selection:

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = ConfigPage.ID then
  begin
    ConfigPage.Edits[0].Enabled := IsComponentSelected('foo');
    ConfigPage.PromptLabels[0].Enabled := ConfigPage.Edits[0].Enabled;

    ConfigPage.Edits[1].Enabled := IsComponentSelected('bar');
    ConfigPage.PromptLabels[1].Enabled := ConfigPage.Edits[1].Enabled;
  end;
end;

A step further would be to hide the boxes instead of disabling them (use Visible instead of Enabled). But then you would have to rearrange the boxes. But that's still easier then re-building the page.

Upvotes: 1

Related Questions