Delphi封装类到DLL
2012-08-30 21:32
141 查看
一个公共单元
类单元,这个写在DLL里面的
DLL的prj
DLL部分就这样了,到EXE部分调用
unit ITest; interface type IT = interface function GetString:string; procedure ShowMsg(p:PChar); procedure Msg; end; implementation end.
类单元,这个写在DLL里面的
unit UTest; interface uses SysUtils, Windows, ITest; type TTest = class(TInterfacedObject,IT) private i:Integer; protected public constructor Create; //override; destructor Destroy; override; function GetString:string; procedure ShowMsg(p:PChar); procedure Msg; published end; implementation constructor TTest.Create; begin i:=0; end; destructor TTest.Destroy; begin inherited; end; function TTest.GetString:string; begin Result := 'Test string'; end; procedure TTest.ShowMsg(p:PChar); begin MessageBox(0,p,'Test',MB_OK); end; procedure TTest.Msg; begin Inc(i); MessageBox(0,'Test MessageBox',PChar(IntToStr(i)),MB_OK); end; end.
DLL的prj
library Test; uses SysUtils, Classes, ITest in 'ITest.pas', UTest in 'UTest.pas'; {$R *.res} function TestCreate:IT; stdcall; begin Result := TTest.Create; end; exports TestCreate; //用此初始化 begin end.
DLL部分就这样了,到EXE部分调用
uses ITest; //引用单元 function TestCreate:IT; stdcall; external 'Test.dll' name 'TestCreate'; //引用DLL函数 //声明作为测试 private AA:IT; BB:IT; procedure TForm1.FormCreate(Sender: TObject); begin AA:= TestCreate; BB:= TestCreate; end; procedure TForm1.Button1Click(Sender: TObject); begin Button1.Caption := AA.GetString; end; procedure TForm1.Button2Click(Sender: TObject); begin AA.ShowMsg('123abc'); end; procedure TForm1.Button3Click(Sender: TObject); begin AA.Msg; end; procedure TForm1.Button4Click(Sender: TObject); begin BB.Msg; end;
相关文章推荐
- Delphi dll窗体封装
- Delphi封装Mdi窗体到Dll并使用插件管理,tabControl制作多页面
- 在dll中delphi中封装窗体(实例)
- Delphi 中的DLL 封装和调用对象技术
- Delphi中的DLL封装和调用对象编写碰到的问题
- [Delphi]DLL封装登录框架实现代码复用
- Delphi 中的DLL 封装和调用对象技术(刘艺,有截图)
- Delphi封装类到DLL
- DELPHI 在DLL中封装的VCL窗体Tab键响应的问题
- [整理]c#简单调用DELPHI DLL封装窗体
- 在dll中delphi中封装窗体(实例)
- Delphi 中的DLL 封装和调用对象技术
- 关于Delphi中DLL封装对象的几种方法整理及体会
- 在dll中delphi中封装窗体(实例)
- Delphi 中的DLL 封装和调用对象技术
- [轉]c#简单调用DELPHI DLL封装窗体
- Delphi 封装窗体封装DLL
- Delphi 创建封装窗体的 DLL 实例
- Delphi 中的DLL 封装和调用对象技术
- 关于Delphi中DLL封装对象的几种方法整理及体会