1

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")
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Rida Shamasneh
  • 767
  • 1
  • 6
  • 16
  • Where does the file exist? On the machine where you compile the installer? Or on the machine where you install the installer? – Martin Prikryl Apr 08 '20 at 11:14
  • It exists on the machine where I compile the installer; Actually - For simplicity - I placed both external file and *.iss in the same directory. – Rida Shamasneh Apr 08 '20 at 11:17

1 Answers1

2

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:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I tried AppVersion={code:GetVersion} and it worked. Thanks a lot – Rida Shamasneh Apr 08 '20 at 11:41
  • So either I did not understand your question or you did not understand my answer. You wrote that the file *"exists the **machine where [you] compile the installer**"*. So you cannot use `{code:...}`. It may work with `Result := '1.1.1'`. But it won't work, if you want to access a file on *"the machine where [you] compile the installer"*. – Martin Prikryl Apr 08 '20 at 12:00
  • ooh,,, i did not read the file yet; But I executed the function and it returned '1.1.1' and assumed file will also work,,,, I don't understand why it won't work on file yet – Rida Shamasneh Apr 08 '20 at 12:08
  • As my answer say in the very first sentence. The code runs on run-time (install-time), so it cannot access a file that exist on compile-time. – Martin Prikryl Apr 08 '20 at 12:35
  • Final solution was to use GetFileVersion(..) API to read the EXE version ..... #define NAND_DECODER_VERSION GetFileVersion("dist\*.exe")" – Rida Shamasneh Apr 09 '20 at 18:02