delphi中dll運用的例子

2021-04-13 08:40:43 字數 3095 閱讀 7227

----------dll工程檔案testdll.pas----------------

library testdll;

uses

sysutils,

classes,

dllfrm in 'dllfrm.pas' ;

//輸出showdllmodalform,showdllform,showcalendar介面方法,以便外部程式呼叫

exports

showdllmodalform, showdllform,showcalendar;

begin

end. 

-----------------dll工程檔案中的窗體檔案dllfrm.pas----------------

unit dllfrm;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, grids, calendar, comctrls, stdctrls, buttons, extctrls;

type

tfrmdll = class(tform)

caldllcalendar: tmonthcalendar;

bevel1: tbevel;

okbin: tbitbtn;

canclebin: tbitbtn;

procedure caldllcalendardblclick(sender: tobject);

procedure okbinclick(sender: tobject);

procedure canclebinclick(sender: tobject);

private

public

end;

procedure showdllmodalform(ahandle: thandle); stdcall; //模式顯示視窗

procedure showdllform(ahandle: thandle); stdcall; //非模式顯示視窗

function showcalendar(ahandle: thandle; acaption: string): tdatetime;stdcall; //模式顯示視窗,返回選擇呼叫的日期

implementation

procedure tfrmdll.okbinclick(sender: tobject);

begin

modalresult := mrok;

end;

procedure tfrmdll.canclebinclick(sender: tobject);

begin

modalresult := mrcancel;

end;

end.

--------------------測試單元檔案ftestdll.pas,用於呼叫dll-----------------

unit ftestdll;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls;

type

//動態態引入dll中的方法: 定義dll中引出的過程型別

tshowdllform = procedure(ahandle: thandle); stdcall;

showdllmodalform = procedure(ahandle: thandle); stdcall;

showcalendar = function (ahandle: thandle; acaption: string): tdatetime;stdcall;

//靜態引入dll中的方法

//procedure showdllmodalform(ahandle: thandle); stdcall external '../5-1/dllshowform.dll';

//procedure showdllform(ahandle: thandle); stdcall external '../5-1/dllshowform.dll';

//function showcalendar(ahandle: thandle; acaption: string): tdatetime; stdcall external '../5-1/dllshowform.dll';

tftest = class(tform)

btnshowmodal: tbutton;

button1: tbutton;

getdateedit: tedit;

btnshow: tbutton;

procedure formcreate(sender: tobject);

procedure btnshowmodalclick(sender: tobject);

procedure btnshowclick(sender: tobject);

procedure button1click(sender: tobject);

procedure formdestroy(sender: tobject);

private

//指向載入後dll控制代碼

dllhandle: thandle;

public

end;

varftest: tftest;

implementation

procedure tftest.formcreate(sender: tobject);

begin

if dllhandle = 0 then

begin

dllhandle := loadlibrary('testdll.dll');

if dllhandle = 0 then

raise exception.create('不能載入dllshowform.dll');

endelse

messagedlg('library already loaded', mtwarning, [mbok], 0);

end;

DELPHI封裝dll的例子,留作紀念

主程式 unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls type tform1 class tform btn1 tbutton p...

Delphi中DLL庫的建立

在delphi環境中,編寫乙個dll同編寫乙個一般的應用程式並沒有太大的區別。事實上作為dll主體的dll函式的編寫,除了在記憶體 資源的管理上有所不同外,並不需要其它特別的手段。一般工程檔案的格式為 program 工程標題 uses 子句 程式體而dlls工程檔案的格式為 library 工程標...

DELPHI中建立呼叫DLL

一,新建 new other dll wizard 二,library new uses sysutils,classes,dialogs procedure dll begin showmessage delphi end exports dll begin end.三,儲存,四,project ...