Search code examples
inno-setuppascalscript

Inno Setup: Execute a Pascal function in [Run] section


At the end of an installation I need to run a Pascal function that updates a flight simulator .cfg file (called .ini file in Inno Setup). The Pascal function exists in its [Code] section and runs correctly. I would like to run this Pascal function in the [Run] section using StatusMsg to tell the user what is going on.

[Run]
Filename: {code:FsxEditSceneryFile|Add#<scenerySpec>}; StatusMsg: "Add scenery to FSX";
; <scenerySpec> is just a place holder of the actual scenery specification!

All works as expected with the exception that Inno Setup forces me to use a string as return value of the Pascal function. However the Filename statement requires a Boolean as return value to specify if the execution was successful (True) or failed (False). This type mismatch produces an error message box at the end of the execution of the Filename statement saying

CreateProcess failed; Code 87. Wrong Parameter.

Any proposal how this could be solved? I know that event functions exist that I could use e.g. CurStepChanged() but I find the StatusMsg mechanism very nice to tell the user what is done by the installation.


Solution

  • You are abusing Filename parameter resolution to execute some code. It's undocumented when the parameter value is resolved. This makes your approach unreliable. You cannot know that the value is resolved, while the StatusMsg is displaying. And moreover, the value must resolve to an executable path anyway. And Inno Setup will try to execute it (hence the error). What you probably do not want. Do not do that.


    Instead, as you already suggested, use the CurStepChanged. You can display the status message from Pascal code by accessing the WizardForm.StatusLabel.

    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssPostInstall then
      begin
        WizardForm.StatusLabel.Caption := 'Installing something...';
        { Install something }
      end;
    end;