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

pascalscript - Inno Setup - Merging implementations of event functions that return boolean (like InitializeSetup)

I use this code to ask for a password: Inno Setup - Move the password page before the welcome page (first page)

And this code for custom language selector:
Inno Setup - Language selector with VCL Styles

When I merge them, it does not work.

I need password before that the language selector, so this is no correct:

function InitializeSetup(): Boolean;
var
  Language: string;
begin
  Result := True;
  Language := ExpandConstant('{param:LANG}');
  if Language = '' then
  begin
    Log('No language specified, showing language dialog');
    SelectLanguage();
    Result := False;
    Exit;
  end
    else
  begin
    Log('Language specified, proceeding with installation');
    Result := AskPassword();
  end;
end;

And this way, with an incorrect password the setup continues.

function InitializeSetup(): Boolean;
var
  Language: string;
begin
  Result := True;
  Language := ExpandConstant('{param:LANG}');
  if Language = '' then
  begin
    Result := AskPassword();
    Log('No language specified, showing language dialog');
    SelectLanguage();
    Result := False;
    Exit;
  end
    else
  begin
    Log('Language specified, proceeding with installation');
  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)

Inno Setup 6

Inno Setup 6 has event attributes features that helps solving this problem.

Just make sure that each of your event implementation have an unique name, e.g. appending unique suffix. And add event attribute with the name of the implemented event.

[Code]
function InitializeSetup(): Boolean;
begin
  Result := ...
end;

<event('InitializeSetup')>
function InitializeSetup2(): Boolean;
begin
  Result := ...
end;

Inno Setup 5

In general, the easiest is to keep both implementations of the event function separate and add one wrapper implementation that call both.

function InitializeSetup1(): Boolean;
var
  Language: string;
begin
  Result := True;
  Language := ExpandConstant('{param:LANG}');
  if Language = '' then
  begin
    Log('No language specified, showing language dialog');
    SelectLanguage();
    Result := False;
    Exit;
  end
    else
  begin
    Log('Language specified, proceeding with installation');
    Result := True;
  end;
end;

function InitializeSetup2(): Boolean;
begin
  Result := AskPassword();
end;

function InitializeSetup(): Boolean;
begin
  { Order the calls the way you want the checks to be performed }
  Result :=
    InitializeSetup2() and
    InitializeSetup1();
end;

For more general discussion of the problem, see
Merging event function (InitializeWizard) implementations from different sources


Though in your specific case, it's more complicated, as you will also need to pass the password from the first instance to the other, similarly to how the language is passed from the first instance to the other.

So actually, the InitializeSetup2 (password) implementation will have to be similar like the InitializeSetup1 (language), not to ask for the password again.

I actually do not really understand, why you complicate the things so much by not asking for language before the password. It would actually make sense. To get a localized password prompt.


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

...