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:
A procedure or function can have only one parameter array and it must be the last argument in the procedure or function signature.
A procedure or function code must process a parameter array as a one-dimensional array, each element of which has the same data type as Paramarray.
A parameters array is always optional. The default value is an empty one-dimensional array with the array element type specified for the parameter array.
All arguments preceding the parameter array in the list must be mandatory. A parameter array must be the only optional argument.
// 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: