The rst step in using external code blocks is declaring the function you want to use. Free Pascal supports Delphi syntax, i.e. you must use the external directive. The external directive replaces, in e ect, the code block of the function.
The external directive doesn't specify a calling convention; it just tells the compiler that the code for a procedure or function resides in an external code block. A calling convention modi er should be declared if the external code blocks does not have the same calling conventions as Free Pascal. For more information on the calling conventions section 6.3, page 319.
There exist four variants of the external directive:
Procedure ProcName (Args : TPRocArgs); external;
|
The external directive tells the compiler that the function resides in an external block of code. You can use this together with the f$Lg or f$LinkLibg directives to link to a function or procedure in a library or external object le. Object les are looked for in the object search path (set by -Fo) and libraries are searched for in the linker path (set by -Fl).
Procedure ProcName (Args : TPRocArgs); external 'Name';
|
This tells the compiler that the procedure resides in a library with name 'Name'. This method is equivalent to the following:
Procedure ProcName (Args : TPRocArgs);external;
{$LinkLib 'Name'} |
Procedure ProcName (Args : TPRocArgs); external 'Name'
name 'OtherProcName'; |
This has the same meaning as the previous declaration, only the compiler will use the name 'OtherProcName' when linking to the library. This can be used to give di erent names to procedures and functions in an external library. The name of the routine is case-sensitive and should match exactly the name of the routine in the object le.
This method is equivalent to the following code:
Procedure OtherProcName (Args : TProcArgs); external;
{$LinkLib 'Name'} Procedure ProcName (Args : TPRocArgs); begin OtherProcName (Args); end; |