Search code examples
inno-setuppascalansi

Using {AppVersion} as a parameter for a function in Inno Setup


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;

Solution

  • 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;