1
votes

In my setup I try to generate application version by code, however I don't manage to call it. My setup looks like this:

#define ApplicationVersion GetVersion('Application.exe')

[Setup]
AppVersion={#ApplicationVersion}
VersionInfoVersion={#ApplicationVersion}

...

[Code]

function GetVersion(Param: String): String;
begin
    { some magic ... }
    Result := '1.2.3';
end;

I also tried

[Setup]
AppVersion={code:GetVersion}
VersionInfoVersion={code:GetVersion}

Any idea to achieve the user-function call?

Note, #define ApplicationVersion GetFileVersion('Application.exe') does not work because "Application.exe" does not provide any version information.

1

1 Answers

3
votes

You cannot call Pascal Script code from Inno Setup preprocessor.

Preprocessor is evaluated on compile time, as the very first thing, before even Pascal Script compiler is invoked. While Pascal Code runs on run time.

You can actually generate Pascal Script code by the preprocessor. What kind of implies, that you cannot call it, as Pascal Script code does not even technically exists at the time the preprocessor code is evaluated.


This is actually correct:

[Setup]
AppVersion={code:GetVersion}

Because AppVersion is evaluated on run time, it can include constants, like {code} (what arguably is not a "constant" – but it is in Inno Setup terminology), as documented:

The value of this directive, which may include constants, ...


But you cannot use constants in VersionInfoVersion:

[Setup]
VersionInfoVersion={code:GetVersion}

Because VersionInfoVersion is evaluated on compile time, as its value is stored into installer executable header.


But there's hardly anything that cannot be implemented in preprocessor. But you have to tell us what you actually want to do.