|
盒子资源分类 |
![]() |
|
|
|
使用DLL封装业务逻辑 |
![]() |
关键字:opeData DLL 封装 业务逻辑 |
来 自:原创 |
平 台:Win2k/XP/NT,Win2003 |
下载所需:0 火柴 |
深浅度:中级 |
完成时间:2006/10/29 |
发布者:hnxxcxg |
发布时间:2006/10/29 |
编辑器:DELPHI7 |
语 种:简体中文 |
分 类:数据库 |
下载浏览:3946/14991 |
|
|
|
|
{ CopyRight (c) 2006.10.27 咏南工作室 ToDo: 使用DLL封装企业业务逻辑 作者: 陈新光 邮箱: hnxxcxg@yahoo.com.cn }
{ 界面部分和业务部分物理分离。将业务部分和界面部分分别编译成dll和exe可执行文件。
定义一个接口部分以实现界面部分和业务部分之间通讯。接口部分可使用接口或抽象类来实现。一定要保持接 口的稳定,轻易不要改变接口单元中的内容。还可通过预留接口来满足未来功能增长的需求。
经常变动的通常是业务部分,通过修改DLL封装对象的实现方法来升级DLL,无需重新修改和编译界面部分的Exe文件。 }
//---------- { 业务逻辑单元 }
unit cl;
interface
uses sysutils, dialogs, classes, forms, it; //引用接口单元
type tTest = class(Tinterfacedobject, Ii) public procedure say; procedure say2; procedure say3; //预留接口 end;
implementation
{ tTest }
procedure tTest.say; begin showmessage('hello'); end;
procedure tTest.say2; begin application.MessageBox('hello', 'dll', 64); end;
procedure tTest.say3; begin //showmessage('预留接口'); { 预留接口是为了应付未来客户对新功能的增加需求. 例如: 将第一行的"//"注释符去掉. 然后只要重新编译"dll.dll", 无须重新编译客户端程序. 客户端即增加了此项新功能. } end;
end. //----------
//---------- { 接口单元 也可使用抽象类作接口单元,但接口是最好的。 }
unit It;
interface
type Ii = interface ['{8C8C7999-0B73-4A85-B89E-3D8A8336FF06}'] //GUID可注释掉(可要可不要),非com项目建议去掉 procedure say; procedure say2; procedure say3; end;
implementation
end. //----------
//---------- { 动态链接库工程文件 请注意这里使用DLL封装对象的技巧, 对象在dll建立 }
library dll;
uses SysUtils, dialogs, Classes, cl in 'cl.pas', //引用业务单元 It in 'It.pas'; //引用接口单元
{$R *.res}
function hello: Ii; begin result := tTest.Create; end;
exports hello;
begin end. //----------
//---------- { 客户端工程文件 } program Project1;
uses Forms, Unit1 in 'Unit1.pas' {Form1}, It in 'It.pas'; //引用接口单元
{$R *.res}
begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. //----------
//---------- { 客户端界面单元 真正的瘦客户端,不包含任何企业逻辑代码 }
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, it; //引用接口单元
type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private m: Ii; //定义变量 public { Public declarations } end;
var Form1: TForm1; function hello: ii; external 'dll.dll'; //装载dll.dll
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin m := hello; m.say; m := nil; end;
procedure TForm1.Button2Click(Sender: TObject); begin m := hello; m.say2; m := nil; end;
procedure TForm1.Button3Click(Sender: TObject); begin m := hello; m.say3; m := nil; end;
end. //---------- |
![]() |
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们! |
相关文章 |
|
![]() |
|
相关评论 |
![]() |
共有评论6条
当前显示最后6条评论
|
hsgrass |
2006/10/31 8:15:38 |
我感觉缺少: 共享数据库连接(二层,三层) 共用公共功能(调用规则) 统一界面 .... 还有很多需要学习:) |
jpweidmann |
2006/11/1 19:40:22 |
值得我学习 谢谢 |
hnxxcxg |
2006/12/28 11:28:52 |
To hsgrass 新发布了一套源代码,应该可以满足你的要求了 |
hnxxcxg |
2007/1/9 12:12:14 |
此篇只是简单的演示,实际开发请参考《DLL封装业务逻辑源码》 |
tkfy602 |
2007/7/20 11:22:52 |
学习ing... |
porn12345 |
2008/5/10 13:26:39 |
刚下了 学习中 努力中 |
我要发表评论 |
查看全部评论 |
|
|
|