For a description of formal parameter lists, see chapter Procedures. The two following examples are valid type declarations:
Procedural types
![]()
![]()
![]()
![]()
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:
Procedure printit (Var X : Integer); begin WriteLn (x); end; ... P := @printit; Func := @Pi;From this example, the difference 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 you use the -So switch, in which case you can drop the address operator.) Remark that the modifiers concerning the calling conventions (cdecl, pascal, stdcall and popstack stick to 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 P := @printit; end.Because the TOneArgCcall type is a procedure that uses the cdecl calling convention. At the moment, the method procedural pointers (i.e. pointers that point to methods of objects, distinguished by the of object keywords in the declaration) are still in an experimental stage.