Rida Shamasneh
Rida Shamasneh

Reputation: 826

Inno Setup: Overriding [Setup] parameters based on user-defined functions

I am trying to configure AppVersion parameter in [Setup] section based on a string which is stored in an external text file.

To accomplish that; I tried to write a function which opens that external file and returns the version; So that later I can utilize the returned version for setting multiple parameters.

#define APP_NAME "blah blah"
#define APP_VERSION "4.0.1"

[Setup]
AppName={#APP_NAME}
;;; AppVersion={#APP_VERSION} ;;; This works
AppVersion=GetVersion() ;;; This does not work as I am expecting

[Code]
; Basic example
function GetVersion(): string;
var 
  FileLines: TArrayOfString;
begin
  Result := '1.1.1'
end;

However, this did not work. Inno Setup did not execute the function. It actually used the function name (i.e. GetVersion()) as the version itself.

My question: Does Inno Setup support such behavior?


Update: I figured out that I can get the version from EXE itself instead of opening a text file and reading the version from it.

#define NAND_DECODER_VERSION GetFileVersion("dist\*.exe")

Upvotes: 1

Views: 739

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202098

Constants, including scripted "constants", are evaluated on run-time (install-time).

If you need to run a code on compile-time, you need to use the preprocessor.

Some related questions with examples:

Upvotes: 2

Related Questions