使用dll文件中封装的窗口
文章摘要:
编写软件时常常使用到dll文件,本文就使用dll文件中封装的窗口来说说delphi中在dll如何封装窗口,如何调用dll中封装的窗口,及mdi-child在dll中载入并使用
一、在dll中封装窗口
打开delphi新建一个dll工程,保存为usedll,生成代码
|
library usedll; { important note about dll memory management: sharemem must be the uses {$r *.res} begin |
新建一个窗体,添加一个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 end object button1: tbutton left = 120 top = 152 width = 75 height = 25 caption = #30830#23450 taborder = 0 onclick = button1click end end |
添加一过程:procedure loadform; export;
procedure loadform;
begin
form1 := tform1.create(application);
try
form1.showmodal;
finally
form1.free;
end;
end;
全部完整的代码:
|
library usedll; uses {$r *.res} end. |
|
unit form_unit; interface uses type var implementation {$r *.dfm} procedure tform1.button1click(sender: tobject); 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 end end |
完整的代码如下:
|
unit use_unit; interface uses var {$r *.dfm} procedure tform1.button1click(sender: tobject); end. |