顯式例子:
單位主;
介面
用途
Windows,Messages,Sysutils,變體,類,圖形,控件,表單,表單,
對話框,stdctrls,extctrls,網格,dbgrids,db,dbtables,dbctrls;
類型
tform1 = class(tform)
Button 1:Tbutton;
edit1:tedit;
edit2:tedit;
Image1:司法燈;
DataSource1:tdatasource;
table1:ttable;
table1speciesno:tfloatfield;
table1類別:tstringfield;
table1common_name:tstringfield;
table1speciesname:tstringfield;
table1lengthcm:tfloatfield;
table1length_in:tfloatfield;
table1notes:tmemofield;
table1graphic:tgraphicfield;
dbgrid1:tdbgrid;
過程button1Click(發件人:tobject);
私人的
{私人聲明}
民眾
{公開聲明}
結尾;
//函數getInteger(i:integer):integer; stdcall; ofternal'dllone.dll';
//函數getDouble(f:double):double; stdcall; ofternal'dllone.dll';
tgetDouble =函數(f:double):double; stdcall;
var
form1:tform1;
執行
{$ r *.dfm}
過程tform1.button1Click(發件人:tobject);
var d:double;
dllhandle:thandle;
功能:tgetDouble;
開始
image1.picture.Assign(table1graphic);
table1graphic.Assign(image1.picture);
出口;
dllhandle:= loadLibrary('dllone.dll');
嘗試
@func:= getProcAddress(dllhandle,'getDouble');
//Edit1.text:= inttoStr(getInteger(2));
// d:= getDouble(2.2);
如果分配(@func),則
開始
D:= func(2.2);
edit2.text:= floattostr(d);
結尾;
最後
Freelibrary(dllhandle);
結尾;
結尾;
結尾。
隱式例子:
圖書館dllone;
用途
sysutils,
班級;
{$ r *.res}
函數getDouble -tover(f:double):double; stdcall; ofternal'dlltwo.dll';
函數getint(i:integer):integer; stdcall; ofternal'dlltwo.dll';
函數getInteger(i:integer):integer; stdcall;
開始
結果:= getint(i);
結尾;
函數getDouble(d:double):double; stdcall;
開始
結果:= getDouble -tark(d);
結尾;
出口
getinteger,
getDouble;
開始
結尾。
圖書館dlltwo;
{關於DLL內存管理的重要說明:ShareMem必須是
圖書館中的第一個單元使用條款和您的項目(選擇
project-viev源)使用子句,如果您的DLL導出任何程序或
將字符串作為參數或函數結果傳遞的函數。這
適用於向您的DLL傳遞的所有字符串,即使是那些
嵌套在記錄和類中。 ShareMem是接口單元
borlndmm.dll共享內存管理器,必須將其部署
與你的dll。要避免使用borlndmm.dll,請傳遞字符串信息
使用PCHAR或短串參數。 }
用途
sysutils,
班級;
{$ r *.res}
函數getDouble -tover(d:double):double; stdcall;
開始
結果:= D;
結尾;
函數getint(i:integer):integer; stdcall;
開始
結果:= i;
結尾;
出口
getDoublext,
getint;
開始
結尾。