inno-setuppascalscript

"Required function or procedure ... not found" when implementing Inno Setup scripted constant to read a selected file from CreateInputFilePage


I'm building a setup with Inno Setup. I try to copy to my install folder a file selected from the CreateInputFilePage but it fails.

this is my code :

[Files]
Source: "{code: getConfigPath}"; DestDir: "{app}"; DestName: "config.json"; Flags: external

the line above throws

required function or procedure 'getConfigPath' not found

[Code]
var
  ConfigPage: TInputFileWizardPage;
  configPath: String;
  
procedure InitializeWizard;
begin
  ConfigPage := CreateInputFilePage(wpSelectDir,
    'Fichier de configuration personnalisé',
    'Sélectionnez le fichier config.json à utiliser.',
    'Ce fichier sera copié à la racine de l’installation.');

  ConfigPage.Add('Fichier JSON requis :',
    'Fichiers JSON (*.json)|*.json|Tous les fichiers (*.*)|*.*',
    '.json');
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    if ConfigPage.Values[0] <> '' then
    begin
      configPath := ConfigPage.Values[0];
    end;
  end;
end;

function getConfigPath(): String;
begin
  Result := ConfigPath;
end;

I'm aware of this question but I've already the external keyword and bypass getConfigPath() with

[Files]
Source: "{ConfigPage.Values[0]}"; DestDir: "{app}"; DestName: "config.json"; Flags: external

doesn't work either.


Solution

  • The literal compiler error that your code leads to is:

    Required function or procedure ' getConfigPath' not found. Compile aborted.

    Note the space before the "getConfigPath". The correct syntax should have no space after the colon:

    {code:getConfigPath}
    

    Once you fix that, you will have another problem:
    "Identifier Expected" or "Invalid Prototype" when implementing a scripted constant in Inno Setup

    The correct function declaration is:

    function getConfigPath(Param: String): String;