The structure of a DLL is identical to that of a program, except that a DLL begins with the reserved word library (instead of program).
The following example shows a DLL with two exported functions, Min and Max.
function Min(X, Y: Integer): Integer; stdcall;
if X < Y then Min := X else Min := Y;
function Max(X, Y: Integer): Integer; stdcall;
if X > Y then Max := X else Max := Y;
If you want your DLL to be available to applications written in other languages, it抯 safest to specify stdcall in the declarations of exported functions. Other languages may not support Object Pascal抯 default register calling convention.
DLLs can be built from multiple units. In this case, the library source file is frequently reduced to a uses clause, an exports clause, and the DLL抯 initialization code. For example,
uses EdInit, EdInOut, EdFormat, EdPrint;
DoneEditors index 17 name Done,
InsertText name Insert,
DeleteSelection name Delete,
PrintSelection name Print,
You can put exports clauses in the interface or implementation section of a unit. Any library that includes such a unit in its uses clause automatically exports the routines listed the unit抯 exports clauses梬ithout the need for an exports clause of its own.
Only routines that a library explicitly exports are available for importing by other libraries or programs.