_________________________________________________________________________________________________________
Procedural types
___________________________________________________________________
For a description of formal parameter lists, see chapter 10, page 348. The two following examples are valid type declarations:
Type TOneArg = Procedure (Var X : integer);
TNoArg = Function : Real; var proc : TOneArg; func : TNoArg; |
One can assign the following values to a procedural type variable:
Given these declarations, the following assignments are valid:
Procedure printit (Var X : Integer);
begin WriteLn (x); end; ... Proc := @printit; Func := @Pi; |
From this example, the di erence with Turbo Pascal is clear: In Turbo Pascal it isn't necessary to use the address operator (@) when assigning a procedural type variable, whereas in Free Pascal it is required (unless the -So switch is used, in which case the address operator can be dropped.)
Remark: The modi ers concerning the calling conventions must be the same as the declaration; i.e. the following code would give an error:
Type TOneArgCcall = Procedure (Var X : integer);cdecl;
var proc : TOneArgCcall; Procedure printit (Var X : Integer); begin WriteLn (x); end; begin Proc := @printit; end. |
Because the TOneArgCcall type is a procedure that uses the cdecl calling convention.