Function calls are part of expressions (although, using extended syntax, they can be statements too). They are constructed as follows:
_________________________________________________________________________________________________________
Function calls
___________________________________________________________________
The variable reference must be a procedural type variable reference. A method designator can only be used inside the method of an object. A qualified method designator can be used outside object methods too. The function that will get called is the function with a declared parameter list that matches the actual parameter list. This means that
If no matching function is found, then the compiler will generate an error. Depending on the fact of the function is overloaded (i.e. multiple functions with the same name, but different parameter lists) the error will be different. There are cases when the compiler will not execute the function call in an expression. This is the case when assigning a value to a procedural type variable, as in the following example:
Type FuncType = Function: Integer; Var A : Integer; Function AddOne : Integer; begin A := A+1; AddOne := A; end; Var F : FuncType; N : Integer; begin A := 0; F := AddOne; { Assign AddOne to F, Don't call AddOne} N := AddOne; { N := 1 !!} end. |
If F = AddOne Then DoSomethingHorrible; |
If F = @AddOne Then WriteLn ('Functions are equal'); |
If F()=Addone then WriteLn ('Functions return same values '); |