Formal Parameters

Formal parameters are the identifiers, which take the values of actual parameters specified during calling of the subprogram.

Parameters may be passed into the program either by reference or by value. If a formal parameter is described as a parameter by reference, the actual parameter must be a variable or an object field. If a formal parameter is described as a parameter by value, the actual parameter must be an expression. The description of a formal parameter by reference must be preceded by the VAR keyword.

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 (function).

$ FormalParameters = [FPSection {";" FPSection}]

$ FPSection = [VAR] ( ident ":" FormalType ["="expression] | ident {"," Ident} ":" FormalType | PARAMARRAY ArraySection )

$ FormalType = ClassType

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

Sub MyProc(a: Integer; Var b: String; c: String = "a");

Begin

//Set of operators

End Sub MyProc;

The A parameter is required and must be an integer. A string variable should be passed as the B parameter. The C parameter is optional, by default, the a letter is passed as its value.

Sub MyProc1(a: Integer; Var b: String; Paramarray c: Array Of Double);

Begin

//Set of operators

End Sub MyProc1;

The A parameter is required and must be an integer. A string variable should be passed as the B parameter. Then a real number array can be passed to the procedure. Use the C array to work with them.

See also:

Describing Procedures and Functions