Skip to content

Flow documentation · legacy product

Functions ​

Functions are unit of code that perform a certain task. They are pre-compiled within the script engine ready for use.

There are two types of functions;

Functions

A function normally takes some Parameters(input) and returns a result (output). These are declared with the keyword Function as in the following

pascal
Function IntToStr(Value: Integer): string;

The above declaration can be broken down as

Function keyword indicates it is a function that will return a result

IntToStr is the name of the function. This is what you would type into your code

(Value: Integer) is a list of parameters (input). The part before the colon is the name of the parameter, the second part is the data type. Individual parameters are separated with a semi colon (or if they are of the same type a comma)

: string indicates the data type of the function result

Procedures

A Procedure is a function that does not return a result. It normally takes some Parameters (input). These are declared with the keyword Procedure as in the following

pascal
procedure LogInfo (aMesg : string);

The above declaration can be broken down as

Procedure keyword indicates it is a procedure and will not return a result

LogInfo is the name of the procedure. This is what you would type into your code

(aMesg : string) is a list of parameters (input). The part before the colon is the name of the parameter, the second part is the data type. Individual parameters are separated with a semi colon (or if they are of the same type a comma)

Some procedures will modify the parameters passed in. In this way a procedure can be thought of as returning a result. If this is the case the parameter will be prefixed with the keyword var. An example of this is the Delete procedure declared as

pascal
procedure Delete(var S: string; Index, Count:Integer);.

The S parameter is declared with the keyword var therefore whatever variable you pass here as the parameter will be modified (in this case by deleting the given number of characters). Any use of the variable after the procedure call will return the modified value.

TIP

A function is called a Procedure when it does not return a result. However throughout this guide we use the term function when referring to either a Function or Procedure

Calling Functions and Procedures ​

You use a Function/Procedure within your script simply by entering its name and providing the appropriate parameters.

When calling functions or procedures that have multiple Parameters you pass them separated using a comma. It is only within the declaration, as shown in the above examples, that parameters are separated with a semi-colon. The below examples show you how to call a function or procedure.

Example Function calls
pascal
Value := IntToStr(MyFloatVariable);

calls the IntToStr function passing in one parameter and assigns the result to the Value variable.

pascal
Value := TaxAmount(MyTotalVariable,12.5);

calls the TaxAmount function passing in two parameters separated by a comma.

Normally a function is used on the right hand side of an assignment operator (:=). This assigns the result of the function to the variable on the left of the assignment operator (Refer Assignment)

Example Procedure calls
text
LogInfo('This is the text to log');

calls the LogInfo procedure passing in one parameter.

text
Delete(MyStringVariable,1,15);

calls the Delete procedure passing in three parameters. This is an example of a procedure that modifies the input parameter. At the end of this procedure call the MyStringVariable will have the first 15 characters deleted. (Refer Delete)

Procedures cannot be used on the right hand side of an assignment operator. This is because a procedure does not return a result, therefore it cannot be assigned to a variable (Refer Assignment)