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
438 views
in Technique[技术] by (71.8m points)

pascalscript - 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;
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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

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

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.


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

...