Search code examples
inno-setuppascalscript

Inno Setup - Pascal code visibility - "Unknown identifier" error


I have a file in my installer with an AfterInstall action like so:

AfterInstall: UpdateImageLoaderConfigValues()

And I would like the procedure to call the same Pascal Script function twice as I can't have two AfterInstall actions as far as I am aware, so I have set this up like so:

procedure UpdateImageLoaderConfigValues();
begin
  SaveValueToXML(ExpandConstant('{app}\ImageLoader.exe.config'),{#ImageLoaderLastConfigurationPath}, ExpandConstant('{app}/Configurations'))
  SaveValueToXML(ExpandConstant('{app}\ImageLoader.exe.config'),{#ImageLoaderLastImagePath}, ExpandConstant('{app}/Images'))
end;

And my function SaveValueToXML has a signature:

function SaveValueToXML(const AFileName, APath, AValue: string);

The problem is that compilation fails because of

Unknown identifier 'SaveValueToXML'

error at the points in UpdateImageLoaderConfigValues where I am trying to use this function.

How can I make SaveValueToXML visible to UpdateImageLoaderConfigValues?


Solution

  • You have to define the SaveValueToXML before the UpdateImageLoaderConfigValues:

    [Files]
    Source: ...; AfterInstall: UpdateImageLoaderConfigValues()
    
    [Code]
    
    function SaveValueToXML(const AFileName, APath, AValue: string);
    begin
      { ... }
    end;
    
    procedure UpdateImageLoaderConfigValues();
    begin
      SaveValueToXML(ExpandConstant('{app}\ImageLoader.exe.config'),{#ImageLoaderLastConfigurationPath}, ExpandConstant('{app}/Configurations'))
      SaveValueToXML(ExpandConstant('{app}\ImageLoader.exe.config'),{#ImageLoaderLastImagePath}, ExpandConstant('{app}/Images'))
    end;
    

    For others, who arrive here with the same error message, but on a variable identifier, rather than on a function or procedure call, , see Inno Setup Pascal script problem... "Unknown Identifier".