Method Parameters

The parameters of a method, if any, are declared by the method's formal parameter list.

formal-parameter-list:

formal-parameters   

formal-parameters:

fixed-parameters

fixed-parameters   ;   parameter-array

parameter-array

fixed-parameters:

fixed-parameter-block

fixed-parameters   ;   fixed-parameter-block

fixed-parameter-block:

attributesopt   parameter-modifieropt   parameter-list   :   type

parameter-list:

identifier

parameter-list   ,   identifier

parameter-modifier:

Var

Out

parameter-array:

attributesopt   ParamArray   identifier   :   array-type

The formal parameter list consists of parameter descriptions, of which only the last may be a parameter-array.

A method declaration creates a new declaration space for parameters and local variables.

A method invocation creates a copy, specific to that invocation, of the formal parameters and local variables of the method. Formal parameters are indicated by actual values specified in argument list when invoking the method. Within the body of a method, its parameters can be referenced by identifying their names. A simple name notation is used.

There are four kinds of formal parameters:

Except for allowing a variable number of arguments in an invocation, a parameter array is precisely equivalent to a value parameter of the same type.

Example

Class MethodParams
    //Parameter i is passed by value
    //Parameter j is passed by reference
    Public Sub A(i: integer; Var j: integer);
    Begin
        
    End Sub;
    
    //Output parameter i
    Public Sub B(Out i: integer);
    Var
        Result: integer;
    Begin
        //Procedure code
        i := Result;
    End Sub;
    
    //Parameter-array Arr
    Public Sub C(Paramarray Arr: array Of double);
    Begin
        
    End Sub;
End Class;

Sub Test();
Var
    Obj: MethodParams = New MethodParams();
    Result: integer;
    Arr: array Of double = New double[3];
Begin
    Obj.A(1Var Result);
    Obj.B(Out Result);
    Arr[0] := 1;
    Arr[1] := 2;
    Arr[2] := 3;
    Obj.C(Arr);
End Sub;

See also:

Methods