The external modifier can be used to declare a function that resides in an external object file. It allows to use the function in some code, and at linking time, the object file containing the implementation of the function or procedure must be linked in.
_________________________________________________________________________________________________________
External directive
___________________________________________________________________
It replaces, in effect, the function or procedure code block. As an example:
program CmodDemo; {$Linklib c} Const P : PChar = 'This is fun !'; Function strlen (P : PChar) : Longint; cdecl; external; begin WriteLn ('Length of (',p,') : ',strlen(p)) end. |
Remark: The parameters in our declaration of the external function should match exactly the ones in the declaration in the object file. If the external modifier is followed by a string constant:
external 'lname'; |
The name that the function has in the library can also be specified:
external 'lname' name 'Fname'; |
external 'lname' Index Ind; |
Finally, the external directive can be used to specify the external name of the function :
{$L myfunc.o} external name 'Fname'; |