一、在DLL中封装窗口
打开Delphi新建一个DLL工程,保存为usedll,生成代码
library usedll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes;
{$R *.res}
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
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
SysUtils,
Classes,
Form_Unit in 'Form_Unit.pas' ;
{$R *.res}
exports
LoadForm index 1;
begin
end.
unit Form_Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ApplicationName: String;
procedure LoadForm(Handle: THandle; AppName: ShortString); export;
implementation
{$R *.dfm}
procedure LoadForm(Handle: THandle; AppName: ShortString);
begin
Application.Handle := Handle;
ApplicationName := AppName;
Form1 := TForm1.Create(Application);
try
Form1.ShowModal;
finally
Form1.Free;
end;
end;
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
end
end
完整的代码如下:
unit Use_Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure LoadForm; external 'usedll.dll' index 1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadForm;
end;
end.
三、MDI-Child在DLL中载入并使用
如果是MDI-Child又如何在DLL中载入并使用呢,下面就这个问题说说使用DLL文件中封装的窗口。
新建一个DLL工程,保存为mdidll,再新建一个窗体,FormStyle设为fsMDIChild,如下:
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 = fsMDIChild
OldCreateOrder = False
Position = poDefault
Visible = True
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
end
Top
子单元
unit mdi_Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
MyParentForm: TForm;
MyParentApplication: TApplication;
end;
var
DllApplication: TApplication;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
end.
dll
library mdidll;
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
mdi_Unit in 'mdi_Unit.pas' ;
procedure LoadChild(ParentApplication: TApplication; ParentForm: TForm); export; stdcall;
var
Form1: TForm1;
DllProc: Pointer;
begin
Application:=ParentApplication;
Form1:=TForm1.Create(ParentForm);
Form1.MyParentForm:=ParentForm;
Form1.MyParentApplication:=ParentApplication;
Form1.Show;
end;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;
end;
{$R *.res}
exports
LoadChild;
begin
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.
编译后生成mdidll.dll文件。
使用DLL中的MDI-Child窗口如下:
新建一个工程,主窗口设置如下FormStyle设为fsMDIForm:
object Form1: TForm1
Left = 192
Top = 133
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charse
没有合适的资源?快使用搜索试试~ 我知道了~
delphi简易学生管理系统(附带成绩)
共77个文件
~pas:9个
pas:9个
~dfm:9个
5星 · 超过95%的资源 需积分: 10 25 下载量 110 浏览量
2010-06-10
17:59:45
上传
评论
收藏 688KB RAR 举报
温馨提示
delphi做的学生管理系统,简易使用,包含班级模块,课程模块,学生管理,成绩管理,需要连接数据库
资源推荐
资源详情
资源评论
收起资源包目录
student.rar (77个子文件)
student
DB
student 1.02MB
unit
ufrmmain.ddp 51B
student.cfg 478B
ufrmmain.dfm 626B
student.dpr 199B
student.~dpr 199B
ufrmmain.~pas 2KB
ufrmmain.pas 2KB
student.dof 3KB
student.res 876B
ufrmmain.~ddp 51B
ufrmmain.~dfm 626B
ufrmmain.dcu 5KB
dlltxt.txt 14KB
output
student.exe 360KB
dllstudent.dll 932KB
dllunit
unit
ufrmcourse.ddp 51B
ufrmscoreedit.ddp 51B
ufrmclassedit.~ddp 51B
ufrmscore.dfm 8KB
ufrmcourseedit.dfm 4KB
ufrmcourse.dcu 7KB
ufrmstudent.pas 8KB
ufrmcourse.~ddp 51B
ufrmscoreedit.~dfm 15KB
dllstudent.dof 3KB
ufrmcourseedit.~ddp 51B
ufrmcourse.~pas 2KB
ufrmscoreedit.~ddp 51B
ufrmscore.pas 6KB
ufrmstudent.dcu 10KB
ufrmstudent.~dfm 9KB
ufrmscore.~pas 6KB
dllstudent.~dpr 3KB
ufrmstdntedit.~dfm 7KB
ufrmclass.~dfm 5KB
ufrmstudent.dfm 9KB
ufrmstudent.~ddp 51B
ufrmcourse.pas 3KB
ufrmscore.~ddp 51B
ufrmclass.ddp 51B
ufrmstdntedit.~pas 6KB
ufrmcourseedit.ddp 51B
ufrmclassedit.~dfm 3KB
dllstudent.dpr 3KB
ufrmcourse.~dfm 5KB
ufrmstdntedit.ddp 51B
ufrmclass.~pas 3KB
ufrmclassedit.~pas 3KB
ufrmcourseedit.pas 3KB
ufrmscoreedit.dfm 15KB
ufrmstudent.~pas 8KB
ufrmscoreedit.pas 16KB
dllstudent.cfg 457B
ufrmstdntedit.dcu 12KB
ufrmcourseedit.~pas 3KB
ufrmcourse.dfm 5KB
ufrmcourseedit.dcu 8KB
ufrmstdntedit.~ddp 51B
ufrmscore.ddp 51B
ufrmstudent.ddp 51B
ufrmscoreedit.dcu 16KB
ufrmcourseedit.~dfm 4KB
ufrmclassedit.ddp 51B
ufrmscore.~dfm 8KB
ufrmclassedit.dcu 8KB
ufrmclassedit.pas 3KB
ufrmclass.~ddp 51B
dllstudent.res 876B
ufrmclassedit.dfm 3KB
ufrmclass.dcu 7KB
ufrmstdntedit.dfm 7KB
ufrmclass.pas 3KB
ufrmscoreedit.~pas 15KB
ufrmstdntedit.pas 6KB
ufrmclass.dfm 5KB
ufrmscore.dcu 9KB
共 77 条
- 1
资源评论
- u0109958232013-09-19对于我这种新手帮助很大~
yulongsheng123
- 粉丝: 3
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 微信小程序 - 同乐居商城:购物车合算源码
- 1、根据输入的三条边值判断能组成何种三角形,并设计测试数据进行判定覆盖测试 三条边为变量a、b、c,范围为1≤边值≤10,不在范
- SQL server 练习题目8道(小白教学).zip
- Python 手写实现 iD3 决策树算法-根据信息增益公式.zip
- 411675952289057车联助手-小窗版(三星)3.5.1.apk
- 三种快速排序方法合并在一个文件中以便直接运行的Python代码示例
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功