Pascal Scripting: Check Parameters

There is one optional parameter that is supported by all sections whose entries are separated into parameters. This is:


The name of a check function that determines whether an entry has to be processed or not. The function must either be a custom function in the [Code] section or a support function.

Besides a single name, you may also use boolean expressions. See Components and Tasks parameters for examples of boolean expressions.

For each check function, may include a comma separated list of parameters that Setup should pass to the check function. Allowed parameter types are String, Integer and Boolean. String parameters may include constants. These constants will not be automatically expanded. If you want to pass an expanded constant, there's one special support function that may be called from within a parameter list for this: ExpandConstant.

Source: "MYPROG.EXE"; DestDir: "{app}"; Check: MyProgCheck
Source: "A\MYFILE.TXT"; DestDir: "{app}"; Check: MyDirCheck(ExpandConstant('{app}\A'))
Source: "B\MYFILE.TXT"; DestDir: "{app}"; Check: DirExists(ExpandConstant('{app}\B'))

All check functions must have a Boolean return value. If a check function (or the boolean expression) returns True, the entry is processed otherwise it's skipped.

Setup might call each check function several times, even if there's only one entry that uses the check function. If your function performs a lengthy piece of code, you can optimize it by performing the code only once and 'caching' the result in a global variable.

A check function isn't called if Setup already determined the entry shouldn't be processed.

A check function for a [Files] section entry using a wildcard but not the external flag is called once per file matching the wildcard, instead of once per entry. Use CurrentFileName to check for which file the function is called.

Here is an example of a [Code] section containing the check functions used above. Function DirExists is a support function and therefore not included in this [Code] section.

  MyProgChecked: Boolean;
  MyProgCheckResult: Boolean;

function MyProgCheck(): Boolean;
  if not MyProgChecked then begin
    MyProgCheckResult := MsgBox('Do you want to install MyProg.exe to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
    MyProgChecked := True;
  Result := MyProgCheckResult;

function MyDirCheck(DirName: String): Boolean;
  Result := DirExists(DirName);