5

So I have a function that is updating some XML and I would like to pass the {AppVersion} that has been set in the [Setup] part of the script as a constant to this function

I have tried

MyFunction(ExpandConstants({AppVersion})

But this gives me an error? How do I pass this constant to my function correctly

My Code

[Files]
Source: ".\Source\myfile.txt"; DestDir: "{app}\System"; AfterInstall: MyFunction('{#SetupSetting("AppVersion")}')

[Setup]
AppId=MyApp
AppName=My Application
AppVersion=011
DefaultDirName=C:\MyApp

[Code]
procedure MyFunction(Text: String);
begin
  MsgBox(Text, mbInformation, MB_OK);
end;
JKennedy
  • 18,150
  • 17
  • 114
  • 198

1 Answers1

15

Use the SetupSetting preprocessor function for expanding [Setup] section directive values:

MyFunction('{#SetupSetting("AppVersion")}');

A short proof:

[Setup]
AppName=My Program
AppVersion=1.2.3.4
DefaultDirName={pf}\My Program

[Code]
procedure InitializeWizard;
begin
  MsgBox('AppVersion is: {#SetupSetting("AppVersion")}.', mbInformation, MB_OK);
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • Hi @TLama, Thanks again for the help. I think you're on the right track. See my update to the question for some example code of how I am trying to use this. Currently my code is showing a blank MessageBox rather than one with the version number in it. What am I doing wrong? – JKennedy Nov 06 '14 at 12:25
  • Move your `[Files]` section after the `[Setup]` section. Preprocessor works from top to bottom and it doesn't know the `AppVersion` directive yet. One hint for using preprocessor; you can save the fully preprocessed script if you write a line `#expr SaveToFile("C:\PreprocessedScript.iss")` at the very end of your script (the only parameter is the path where the preprocessed script should be stored). – TLama Nov 06 '14 at 12:32
  • NeverMind I've realised my mistake from [here](http://stackoverflow.com/a/1926709/2987066) the `[Setup]` section must come before the `'{#SetupSetting("AppVersion")}'` line in the iis file – JKennedy Nov 06 '14 at 12:32