DEMO程序说明
提供了两个演示接口
IBplOne=interface
['{E4C1C5FA-C598-4834-9111-26B52634068D}']
function Add(A,B:Integer):integer;
function Sub(A,B:Integer):Integer;
end;
IDllOne=interface
['{0434DE04-07C9-4623-9009-CF7892768431}']
function GetString:string;
procedure SetString(const Str:string);
end;
这里演示了主窗体调用接口IBplOne,调用Dll和BPL里的窗体
Dll窗体调用了IBplOne接口和IDllOne接口,BPL窗体调用了IDllOne接口
其中IBplOne采用接口工厂创建,IDllOne采用单实例工厂创建,所以在Dll窗体调用接口IDllOne与BPL窗体调用接口IDllOne是同一实例
开发步骤
主程序
将工程文件里的Forms替换为uTangramFramework,同时把核心包Tangram_Core加入运行库
如果是通过IDE向导创建的主程序,则这两个步骤就已经做好的了
模块
一个模块要被框架所调用必须引用框架包,同时定义一个TMoudle子类和一个GetModuleClass导出函数,采用向导创建模块这些都会自动创建
Type
TUserModule=Class(TModule)
private
public
Constructor Create; override;
Destructor Destroy; override;
procedure Init; override;
procedure final; override;
procedure Notify(Flags: Integer; Intf: IInterface); override;
class procedure RegisterModule(Reg:IRegistry);override;
class procedure UnRegisterModule(Reg:IRegistry);override;
End;
initialization
//模块子类注册
RegisterModuleClass(TUserModule);
finalization
//模块导出函数
Exports
InstallModule,
UnInstallModule,
GetModuleClass;
然后在包里创建接口定义文件,一般我们把对外开放的接口放到一个公共目录,并加入Delphi搜索路径,这样其它工程也能引用到
unit BplOneIntf;
{$WEAKPACKAGEUNIT ON}
interface
type
IBplOne=interface
['{E4C1C5FA-C598-4834-9111-26B52634068D}']
function Add(A,B:Integer):integer;
function Sub(A,B:Integer):Integer;
end;
implementation
end.
并用向导来创建接口实现单元,接口实现单元会创建接口的实现类,接口实例创建函数,类厂
//接口实现类
Type
TBplOne=Class(TInterfacedObject,IBplOne)//假设你的接口叫IXXX(以下同)
private
protected
{IXXX}
//这里加上你接口方法,然后按Ctrl+Shift+C,实现你的接口...
function Add(A,B:Integer):integer;
function Sub(A,B:Integer):Integer;
Public
End;
implementation
//接口实例创建函数
procedure Create_BplOne(out anInstance: IInterface);
begin
anInstance:=TBplOne.Create;
end;
//类厂注册
var Factory:TObject;
initialization
Factory:=TIntfFactory.Create(IBplOne,@Create_BplOne);
finalization
Factory.Free;
这样模块的编写就完成了,接下来是接口调用
procedure TFrmMain.Button1Click(Sender: TObject);
var intf:IBplOne;
begin
intf:=SysService as IBplOne;
Edit3.Text:=
IntToStr( intf.Add(StrToInt(Edit1.Text),StrToInt(Edit2.Text)) );
end;
procedure TfrmBplOne.Button3Click(Sender: TObject);
var intf:IDllOne;
begin
intf:=SysService as IDllOne;
Edit5.Text:=intf.GetString;
end;
框架采用的是统一的接口调用,一个有定义类厂的接口,就可以通过 SysService as IXXX 的统一方式来调用
运行程序之前要把编译好的框架核心包Tangram_Core.bpl和框架配制工具ConfigTool.exe放到程序目录。
框架默认是采用从XML文件来自动加载模块的,通过框架配制工具,把做好的模块安装一下
视频教程地址:
ERPSYSTEM开发教程01 http://pan.baidu.com/s/1kT7Rb3D
ERPSYSTEM开发教程02 http://pan.baidu.com/s/11xN5s
框架源代码下载地址 http://pan.baidu.com/s/1jGIc2Su
DEMO源代码下载地址 http://pan.baidu.com/s/1bnyEafH