开发者

Extending event functions via #Include directive

I have a base inno-setup script that开发者_C百科 I use as a template for several installers. As part of the base script I have a call to the event function, NextButtonClick.

I would now like to add some additional code to the NextButtonClick event that will only be executed by one of my installers. Is there some way to "extend" the NextButtonClick event? I'm thinking of something along the lines of Python's super() function.

Inno-setup uses Pascal as a scripting language, so perhaps a Pascal expert can offer some insight.


Not directly

Remember the #include directive is just a pre-compiler directive which makes the included file to appear in the place the directive is to the inno setup script compiler.

but To avoid including individual installer code on the template script, you can create a convention to call a procedure in the template.

The only rule you have to follow is that every installer must declare the procedure, even blank. That way, you can customize as per-installer basis while maintaining a neutral template.

Your template may be something like:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := BeforeNextButtonClick(CurPageID);
  //if the per-installer code decides not to allow the change, 
  //this code prevents further execution, but you may want it to run anyway.
  if not Result then
    Exit;  
  //your template logic here

  Result := Anything and More or Other;

  //same here!
  if not Result then
    Exit;

  //calling the per-installer code
  Result := AfternextButtonClck(CurPageID);
end;

Then individual installers may look like this:

function BeforeNextButtonClick(CurPageID: Integer): Boolean;
begin
  //specific logic here
  Result := OtherThing;
end

function AfterNextButtonClick(CurPageID: Integer): Boolean;
begin
  //and here, a blank implementation
  Result := True;
end;

#include MyCodeTemplate.iss

Maybe it is possible to implement a complex approach, I just can't remember if PascalScript supports procedural types and no time to check with inno.

disclaimer all code written directly here to show you the idea, it may not compile.


I'm using the following workaround, which may make things hard to manage eventually, but using version control I'm able to keep a handle on it for now:

In my individual installers, I have a series of #define directives. For example:

#define IncludeSomeFeature
#define IncludeSomeOtherOption

Then in my base template, I use the #ifdef directives to optionally include different pieces of code within the Pascal scripting events:

function NextButtonClick(CurPageID: Integer): Boolean;
var
    ResultCode: Integer;
begin
  Result := True;
  if CurPageID = wpReady then begin
    #ifdef IncludeSomeFeature
        ... some code ...
    #endif
    #ifdef IncludeSomeOtherOption
        ... some more code ...
    #endif
    ... code to run for every installer ...
  end;
end;

The one downside to this approach is that code that the base template will slowly fill up with code that really belongs with the individual installer. However, since these are compile time directives, the resulting setup executables should not get bloated.

Really, though, my biggest problem with this approach is that it just doesn't feel like The Right Way™.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜