在DOS下曾经使用过,在Windows没有用过。
borland pascal 7 中的描述如下:
external (procedure directive)
External declarations allow you to interface with separately compiled
procedures and functions written in assembly language.
The external code is linked with the Pascal unit or program through
$L filename compiler directives.
In procedures and functions imported from DLLs, the external directive
takes the place of the declaration and statement parts that would
otherwise be present.
Examples:
function GetMode: Word
external;//需要事先声明 {$L filename }
procedure SetMode(Mode: Word)
external
$L CURSOR.OBJ
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Dos下是这样使用的,注意路径和文件名要指清楚
在Delphi6 的Help中有如下的描述:
The external directive, which replaces the block in a procedure or function declaration, allows you to call routines that are compiled separately from your program. External routines can come from object files or dynamically loadable libraries.
When importing a C++ function that takes a variable number of parameters, use the varargs directive. For example,
function printf(Format: PChar): Integer
cdecl
varargs;
The varargs directive works only with external routines and only with the cdecl calling convention.
Linking to object files
To call routines from a separately compiled object file, first link the object file to your application using the $L (or $LINK) compiler directive. For example,
On Windows: {$L BLOCK.OBJ}
On Linux: {$L block.o}
links BLOCK.OBJ (Windows) or block.o (Linux) into the program or unit in which it occurs. Next, declare the functions and procedures that you want to call:
procedure MoveWord(var Source, Dest
Count: Integer)
external;
procedure FillWord(var Dest
Data: Integer
Count: Integer)
external;
Now you can call the MoveWord and FillWord routines from BLOCK.OBJ (Windows) or block.o (Linux).
Declarations like the ones above are frequently used to access external routines written in assembly language. You can also place assembly-language routines directly in your Object Pascal source code
for more information, see Inline assembler code.