显式例子:
หน่วยหลัก;
ส่วนต่อประสาน
ใช้
Windows, ข้อความ, sysutils, ตัวแปร, คลาส, กราฟิก, การควบคุม, รูปแบบ,
กล่องโต้ตอบ, stdctrls, extctrls, กริด, dbgrids, db, dbtables, dbctrls;
พิมพ์
tform1 = คลาส (tform)
ปุ่ม 1: tbutton;
Edit1: Tedit;
แก้ไข 2: Tedit;
Image1: timage;
DataSource1: tDataSource;
ตารางที่ 1: ttable;
Table1speciesno: tfloatfield;
Table1Category: TSTRINGFIELD;
table1common_name: tstringfield;
table1speciesname: tstringfield;
table1lengthcm: tfloatfield;
table1length_in: tfloatfield;
ตารางที่ 1notes: tmemofield;
Table1graphic: Tgraphicfield;
dbgrid1: tdbgrid;
ขั้นตอน button1click (ผู้ส่ง: tobject);
ส่วนตัว
{ประกาศส่วนตัว}
สาธารณะ
{ประกาศสาธารณะ}
จบ;
// ฟังก์ชั่น getinteger (i: จำนวนเต็ม): จำนวนเต็ม; stdcall; ภายนอก 'dllone.dll';
// ฟังก์ชั่น getDouble (f: double): double; stdcall; ภายนอก 'dllone.dll';
tgetDouble = function (f: double): double; stdcall;
วาจา
Form1: TFORM1;
การดำเนินการ
{$ r *.dfm}
ขั้นตอน tform1.button1click (ผู้ส่ง: tobject);
var d: double;
Dllhandle: Thandle;
func: 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: = floattostrtr (d);
จบ;
ในที่สุด
Freelibrary (Dllhandle);
จบ;
จบ;
จบ.
隐式例子:
ห้องสมุด dllone;
ใช้
Sysutils
ชั้นเรียน;
{$ r *.res}
ฟังก์ชั่น getDoubleEkext (f: double): double; stdcall; ภายนอก 'dlltwo.dll';
ฟังก์ชั่น getint (i: จำนวนเต็ม): จำนวนเต็ม; stdcall; ภายนอก 'dlltwo.dll';
ฟังก์ชั่น getinteger (i: จำนวนเต็ม): จำนวนเต็ม; stdcall;
เริ่ม
ผลลัพธ์: = getint (i);
จบ;
ฟังก์ชั่น getDouble (d: double): double; stdcall;
เริ่ม
ผลลัพธ์: = getDoubleExt (d);
จบ;
การส่งออก
Getinteger
getDouble;
เริ่ม
จบ.
ห้องสมุด dlltwo;
{หมายเหตุสำคัญเกี่ยวกับการจัดการหน่วยความจำ DLL: Sharemem ต้องเป็น
หน่วยแรกในประโยคการใช้ห้องสมุดของคุณและโครงการของคุณ (เลือก
แหล่งดูโครงการ) ใช้ประโยคหาก DLL ของคุณส่งออกขั้นตอนใด ๆ หรือ
ฟังก์ชั่นที่ผ่านสตริงเป็นพารามิเตอร์หรือผลลัพธ์ของฟังก์ชั่น นี้
นำไปใช้กับสตริงทั้งหมดที่ส่งผ่านไปและกลับจาก DLL ของคุณ-แม้จะเป็นเช่นนั้น
ซ้อนกันในบันทึกและชั้นเรียน Sharemem เป็นหน่วยอินเทอร์เฟซ
borlndmm.dll แชร์ตัวจัดการหน่วยความจำซึ่งจะต้องปรับใช้ตาม
กับ DLL ของคุณ เพื่อหลีกเลี่ยงการใช้ borlndmm.dll ผ่านข้อมูลสตริง
การใช้พารามิเตอร์ PCHAR หรือ ShortString -
ใช้
Sysutils
ชั้นเรียน;
{$ r *.res}
ฟังก์ชั่น getDoubleEkext (D: double): double; stdcall;
เริ่ม
ผลลัพธ์: = d;
จบ;
ฟังก์ชั่น getint (i: จำนวนเต็ม): จำนวนเต็ม; stdcall;
เริ่ม
ผลลัพธ์: = i;
จบ;
การส่งออก
getDoubleExt
Getint;
เริ่ม
จบ.