使用DLL檔案中封裝的視窗

2021-04-02 02:32:54 字數 4911 閱讀 6766

一、在dll中封裝視窗

開啟delphi新建乙個dll工程,儲存為usedll,生成**

library usedll;

uses

sysutils,

classes;

begin

end.

新建乙個窗體,新增乙個label和button,設定如下:

object form1: tform1

left = 192

top = 133

width = 334

height = 221

caption = 'dll'#20013#20351#29992#31383#20307

color = clbtnface

font.charset = default_charset

font.color = clwindowtext

font.height = -11

font.name = 'ms sans serif'

font.style =

oldcreateorder = false

pixelsperinch = 96

textheight = 13

object label1: tlabel

left = 104

top = 80

width = 80

height = 13

caption = 'dll'#20013#20351#29992#31383#20307

endobject button1: tbutton

left = 120

top = 152

width = 75

height = 25

caption = #30830#23450

taborder = 0

onclick = button1click

endend

全部完整的**:

library usedll;

uses

sysutils,

classes,

form_unit in 'form_unit.pas' ;

exports

loadform index 1;

begin

end.

unit form_unit;

inte***ce

uses

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

dialogs, stdctrls;

type

tform1 = class(tform)

label1: tlabel;

button1: tbutton;

procedure button1click(sender: tobject);

private

public

end;

implementation

procedure tform1.button1click(sender: tobject);

begin

self.close;

end;

end.

編譯後生成usedll.dll檔案,至此dll檔案就完成了

二、呼叫dll中封裝的視窗

新建乙個工程,新增乙個button,窗體布局如下:

object form1: tform1

left = 192

top = 133

width = 336

height = 222

caption = 'form1'

color = clbtnface

font.charset = default_charset

font.color = clwindowtext

font.height = -11

font.name = 'ms sans serif'

font.style =

oldcreateorder = false

pixelsperinch = 96

textheight = 13

object button1: tbutton

left = 128

top = 88

width = 75

height = 25

caption = #25171#24320#31383#20307

taborder = 0

onclick = button1click

endend

完整的**如下:

unit use_unit;

inte***ce

uses

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

dialogs, stdctrls;

type

tform1 = class(tform)

button1: tbutton;

procedure button1click(sender: tobject);

private

public

end;

varform1: tform1;

procedure loadform; external 'usedll.dll' index 1;

implementation

procedure tform1.button1click(sender: tobject);

begin

loadform;

end;

end.

三、mdi-child在dll中載入並使用

如果是mdi-child又如何在dll中載入並使用呢,下面就這個問題說說使用dll檔案中封裝的視窗。

新建乙個dll工程,儲存為mdidll,再新建乙個窗體,formstyle設為f**dichild,如下:

object form1: tform1

left = 192

top = 133

width = 344

height = 234

caption = 'mdi'

color = clbtnface

font.charset = default_charset

font.color = clwindowtext

font.height = -11

font.name = 'ms sans serif'

font.style =

formstyle = f**dichild

oldcreateorder = false

position = podefault

visible = true

onclose = formclose

pixelsperinch = 96

textheight = 13

end**如下:

unit mdi_unit;

inte***ce

uses

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

dialogs;

procedure tform1.formclose(sender: tobject; var action: tcloseaction);

begin

action:=cafree;

end;

end.

library mdidll;

uses

windows,

messages,

sysutils,

classes,

graphics,

controls,

forms,

dialogs,

mdi_unit in 'mdi_unit.pas' ;

編譯後生成mdidll.dll檔案。

使用dll中的mdi-child視窗如下:

新建乙個工程,主視窗設定如下formstyle設為f**diform:

object form1: tform1

left = 192

top = 133

width = 544

height = 375

caption = 'form1'

color = clbtnface

font.charset = default_charset

font.color = clwindowtext

font.height = -11

font.name = 'ms sans serif'

font.style =

formstyle = f**diform

menu = mainmenu1

oldcreateorder = false

pixelsperinch = 96

textheight = 13

object mainmenu1: tmainmenu

left = 72

top = 136

object n1: tmenuitem

caption = #26032#24314'(&n)'

onclick = n1click

endend

end**:

unit usemdi_unit;

inte***ce

uses

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

dialogs, menus;

implementation

end.

在dll中delphi中封裝窗體

dll工程library formdll uses sysutils,classes,forms,dllform in dllform.pas dllfrom2 in dllfrom2.pas begin end.dll單元檔案一 unit dllform inte ce uses windows,...

在dll中delphi中封裝窗體 例項

dll工程 library formdll uses sysutils,classes,forms,dllform in dllform.pas dllfrom2 in dllfrom2.pas begin end.dll單元檔案一 unit dllform inte ce uses windows...

封裝原生的JS,vue中封裝全域性使用的函式

function fun fun 這裡的this,指向的是window new fn new 的函式指向的不是window而是指向了該函式新的物件,目的是改變指標,建立物件例項 function fun1 var aa new fun1 aa.x 原型 讓某乙個大類都有某個方法 var arr ar...