sub, endsub directives

Inno Setup Preprocessor

sub, endsub directives

Syntax

sub-directive: sub <ident>
endsub-directive: endsub

Description

sub and endsub directives are used to declare a user defined procedure. Procedure is a closed sequence of ISPP directives and/or script lines, which may be included later once or several times. As of its logic, a user defined procedure is similar to an external file, and a call to a user defined procedure is similar to an inclusion of an external file.

However, procedures can be called from within expressions, whereas inclusion of a file requires a whole directive to be used. Please note, that it is strongly not recommended to call procedures that emit several lines to translation from compound expressions or directives.

A procedure is called by simply specifying its identifier, with which it was declared.

A procedure is not processed in any way untill it is called, so if any errors exist (invalid directives, syntax errors) in the body, they will only pop up when the procedure is called.

Examples

#sub AddFile
  #if Copy(FileName, 1, 1) == "A"
    Source: {#FileName}; DestDir: {app}\A
  #else
    Source: {#FileName}; DestDir: {app}
  #endif
#endsub

More examples

FindFirst function, FileRead function.

See also

User defined macros, if, emit.