Formal Parameters

Formal parameters are the identifiers that take the values of actual parameters specified during calling of procedures or functions.

Parameters can be passed both by reference and by value. If a formal parameter is described as a parameter by reference, the actual parameter must be a variable or an object field. The description of a formal parameter by reference must be preceded by the Var keyword. If a formal parameter is described as a parameter by value, the actual parameter must be an expression.

The argument passed as a parameter value by reference must have the same type as the parameter type. The argument passed as a parameter value by value must have the same type that can be cast to parameter type.

Formal parameters are local for a procedure or function.

A formal parameter, passed by a value, can be optional. A parameter is considered optional if a default value is defined for it. All the optional parameters must follow in the end of the parameter list. A default value cannot be assigned to a parameter list. To specify a parameter array, use the reserved word Paramarray. The following rules are applicable:

Example

// a - parameter passed by value
// b - parameter passed by reference
// c - parameter passed by value. Default value = 'a'
Sub MyProc(a: Integer; Var b: String; c: String = "a");
Begin
    b := c;
    
//Set of statements
End Sub MyProc;

// a - parameter passed by value
// b - parameter passed by reference
// c - array of real type statements
Sub MyProc1(a: Integer; Var b: String; Paramarray c: Array Of Double);
Begin
    
//Set of statements
End Sub MyProc1;

See also:

Procedures and Functions