Exports Keyword
exportsSubroutine
,Subroutine
nameIdentifier
,Subroutine
indexConstant
,Subroutine
indexConstant
nameIdentifier
, ...;
The exports
declaration lists the names or
signatures of subroutines to be exported from a DLL. You can declare
subroutines to export in any unit or in the library’s project
file.
If a subroutine is overloaded, you can specify which subroutine to
export by including the subroutine’s arguments in the
exports
declaration. You can export multiple
overloaded subroutines, but make sure the caller is able to identify
which one it wants to call by assigning a unique name to each
one.
By default, the subroutine is exported under its own name, but you can specify a different name or an index number. If you do not supply an index, Delphi automatically assigns one.
You can use the index
and name
directives for the same exported routine (in that order).
Delphi does not check for duplicate indices, so be careful.
Delphi 5 does not allow the index
directive for
overloaded subroutines.
unit Debug; interface // Simple debugging procedures. Debug messages are written to // a debug log file. You can link this unit into an application, // or use in a DLL. See the External Directive for an example // of how an application can use these procedures from a DLL. procedure Log(const Msg: string); overload; procedure Log(const Fmt: string; const Args: array of const); overload; procedure SetDebugLog(const FileName: string); function GetDebugLog: string; implementation uses SysUtils; var DebugLog: string = 'c:debug.log'; procedure SetDebugLog(const FileName: string); begin DebugLog := FileName; end; function GetDebugLog: string; begin Result := DebugLog; end; procedure Log(const Msg: string); overload; var F: Text; begin AssignFile(F, DebugLog); if FileExists(DebugLog) then Append(F) else Rewrite(F); try WriteLn(F, '[', DateTimeToStr(Now), '] ', Msg); finally CloseFile(F); end; end; procedure Log(const Fmt: string; Args: array of const); overload; begin WriteLn(Format(Fmt, Args)); end; exports GetDebugLog, SetDebugLog, Log(const Msg: string) name 'Log', Log(const Fmt: string; const Args: array of const) name 'LogFmt'; end.