Reading values from custom wizard pages without us

2020-02-13 05:57发布

问题:

On this support page for creating a custom 'CreateInputOptionPage', they suggest storing the values of the page by just assigning them to a variable. Its 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.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "O"
#define MyAppVersion "0.0"
#define MyAppPublisher "O."
#define MyAppURL "http://www.o.com/"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{ED5F31B8-32DD-4175-833A-C6D7CBD90DD9}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={sd}\{#MyAppName}
AllowNoIcons=yes
OutputDir={desktop}
OutputBaseFilename=dummy
Compression=lzma
SolidCompression=yes

[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;

回答1:

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

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.


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.



标签: inno-setup