Free Pascal has support for procedural types, although it differs a little from the Turbo Pascal implementation of them. The type declaration remains the same, as can be seen in the following syntax diagram:
_________________________________________________________________________________________________________
Procedural types
___________________________________________________________________
For a description of formal parameter lists, see chapter 8, page 288. The two following examples are valid type declarations:
Type TOneArg = Procedure (Var X : integer); TNoArg = Function : Real; var proc : TOneArg; func : TNoArg; |
Given these declarations, the following assignments are valid:
Procedure printit (Var X : Integer); begin WriteLn (x); end; ... Proc := @printit; Func := @Pi; |
Remark: The modifiers 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. |