Name

External Directive

Syntax

subroutine declaration; external;
subroutine declaration; external DllName;
subroutine declaration; external DllName name String;
subroutine declaration; external DllName index Constant;

Description

Every subroutine declared in a unit’s interface section must be implemented in the same unit’s implementation section. Subroutines can be implemented with the external directive, which means the actual implementation is in a separate object file or DLL. If no DllName is given, the external implementation must be linked from a compatible object file using the $L or $Link compiler directive.

A DllName must be a string constant. For maximum portability, be sure to include the .dll extension in the DLL’s filename. (Windows NT, for example, requires the file’s extension.) By default, Delphi looks up the subroutine name in the DLL, but you can specify a different name to look up or specify a numeric index.

Example

// Import the debugging procedures that were exported from
// the Debug library. (See the Exports Directive.)
procedure Log(const Msg: string); overload; external 'Debug.dll';
procedure Log(const Fmt: string; const Args: array of const); overload;
    external 'Debug.dll' name 'LogFmt';

See Also

Exports Directive, Index Directive, Name Directive, $L Compiler Directive, $Link Compiler Directive

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.