inno-setuppascalscript

Reading values from custom Inno Setup wizard pages without using global variables


On this support page for creating a custom CreateInputOptionPage, they suggest storing the values of the page by just assigning them to a variable. It's not clear however WHEN this assignment should happen.'

From what I can tell, if you assign this right when you create the page, you will get the default value. This makes sense as when the page is created, user hasn't input any "Input Query"'s yet.

Therefore, I reasoned to assign the values from the page to a variable when the 'Next' button is clicked, using function NextButtonClick(CurPageID: Integer): Boolean;

In order to do that, I needed to access the page's variable (Page.Values[0]) in the NextButtonClick function. Since Page was defined in a different function, is the only way to access those values to have Page be a global variable? That's what I've resolved to do but I was wondering if anyone out there had an alternative to global variables.

Stub of my code so far.

[Code]

var
  Page: TInputOptionWizardPage;
  InstallationTypeIsClient: boolean;

procedure InitializeWizard();
begin
  Page := CreateInputOptionPage(wpWelcome,'Installation Type', 'Select Installation Type', 'No really, do some selecting', True, False)
  Page.Add('Server Install');
  Page.Add('Client Install');
  Page.Values[1] := True;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID=100 then
  begin
    InstallationTypeIsClient := Page.Values[1];
    MsgBox('InstallationTypeIsClient value is ' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
  end;
  Result := True;
end;

Solution

  • Using a global variable to store the reference to the custom page is the correct and the easiest way.

    Related question: Access to custom control from OnClick event of another control in Inno Setup.

    Though it's questionable whether you really need to store the user value to another variable. Just read the value from the custom page at the moment you need it.

    Using global variables in indeed frowned upon, in general. But that's, when you are developing a standalone code. In this case, you are just implementing event hooks for an existing application, so you have no other choice.


    The only other way is to recursively lookup the custom page in child controls of the WizardForm. It's lot of code and quite inefficient.

    See my answer to Inno Setup OnHover event for an example of recursive component iteration.