现在把全文的代码列举如下,其中有一些上面没有给出的代码,但它们也很重要,列在一起方便大家浏览,请仔细查看下面的代码以获得需要的信息,当然本文也仅仅是做为一个简单的例子,举出了一些常见的问题和解决技巧,以及象这样的接口编程的一个可能应用。
接口:
IFoo = interface;
IFooManager = interface
[''''{3A10DC39-4B14-4C61-B657-E445C55408B6}'''']
function CreateAFoo:IFoo;
procedure DelAFoo(id:integer);
function GetFooNum:integer;
function GetFooByID(id:integer):IFoo;
end;
IFoo = interface
//我们要维护的对象,只实现了一个简单的加法运算做为例子
[''''{22C541AA-0BA4-4092-B0EB-D267AB1FF001}'''']
function fooAdd(x,y:integer):integer;
end;
TFoo的声明和实现:
TFoo = class(TMyInterfacedObject,IFoo)
protected
function fooAdd(x,y:integer):integer;
end;
implementation
{ TFoo }
function TFoo.fooAdd(x, y: integer):integer;
begin
result:=x+y;
end;
工厂类的声明和实现:
TFooManager=class(TMyInterfacedObject,IFooManager)
private
FList:array of TFoo;
FooNum:integer;
protected
constructor Create;
function CreateAFoo:IFoo;
procedure DelAFoo(id:integer);
function GetFooNum:integer;
function GetFooByID(id:integer):IFoo;
public
[1] [2] [3] 下一页
[Delphi程序]非COM环境下的接口编程--问题,技巧,应用(一)