显式例子:
单位主;
界面
用途
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;
开始
结尾。