Pascal Scripting: Scripted Constants

Inno Setup

Pascal Scripting: Scripted Constants

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}

  • FunctionName specifies the name of the Pascal script function.
  • Param specifies the string parameter to pass to the function. If you omit Param, an empty string will be passed.
  • If you wish to include a comma, vertical bar ("|"), or closing brace ("}") inside the constant, you must escape it via "%-encoding." Replace the character with a "%" character, followed by its two-digit hex code. A comma is "%2c", a vertical bar is "%7c", and a closing brace is "%7d". If you want to include an actual "%" character, use "%25".
  • Param may include constants. Note that you do not need to escape the closing brace of a constant as described above; that is only necessary when the closing brace is used elsewhere.
Example:
DefaultDirName={code:MyConst}\My Program

Here is an example of a [Code] section containing the MyConst function used above.

[Code]
function MyConst(Param: String): String;
begin
  Result := ExpandConstant('{pf}');
end;

If the function specified by the {code:...} constant is not included in the [Code] section, it must be a support function. Here is an example.

[INI]
FileName: "{app}\MyIni.ini"; Section: "MySettings"; Key: "ShortApp"; String: "{code:GetShortName|{app}}"

See also:
Constants