1

I'm using Inno Setup for my installation and am adding the following function to the existing [Code] section:

function Get64Or32: String;
begin
  if IsWin64 then
  begin
    Result := 'Program Files (x86)';
  end
    else
  begin
    Result := 'Program Files';
  end;
end;

I keep getting the following error:

10:41:08 Invalid prototype for 'Get64Or32'

I have tried several permutations including having the parenthesis after the function name but get the same error each time.

I'm attempting to use this from the [Registry] section to pinpoint the Java location:

Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"JRE_HOME"; ValueData:"C:\{code:Get64or32}\Java\jre_1.8.0_151"; Flags: preservestringtype uninsdeletevalue uninsdeletekeyifempty; Permissions: users-modify;
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Tacitus86
  • 1,314
  • 2
  • 14
  • 36

1 Answers1

2

If you look here Pascal Scripting: Scripted Constants it explains it all. To quote:

The syntax of a {code:...} constant is: {code:FunctionName|Param}

The Pascal script can contain several functions which are called when Setup wants to know the value of a scripted {code:...} constant. The called function must have 1 String parameter named Param, and must return a String or a Boolean value depending on where the constant is used.

The syntax of a {code:...} constant is: {code:FunctionName|Param}

It also provides:

  • An example function:
[Code]
function MyConst(Param: String): String;
begin
  Result := ExpandConstant('{autopf}');
end;
  • An example useage:
[INI]
FileName: "{app}\MyIni.ini"; Section: "MySettings"; Key: "ShortApp"; String: "{code:GetShortName|{app}}"

You don't have to use the parameter but it must be part of the prototype.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • Seems I am still able to simply call {code:MethodName} without the parameter. Though you are correct about the (Param: String) needing to be necessary. it compiled after adding that. – Tacitus86 Jun 01 '21 at 15:18
  • 1
    @Tacitus86 Correct. That linked document says if you omit the | etc. that it will default to an empty string. – Andrew Truckle Jun 01 '21 at 15:21