扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
很多人在接口定义中,喜欢使用派生的方式进行定义。但是我要说的是,接口不应该派生,而应该AS出来。
IInterface = interface
['{00000000-0000-0000-C000-000000000046}']
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
end;


end;
a: IA;
b: IB;
b := TB.Create;
a := IA(b);
b := IB(a);
end;
TB = class(TInterfacedObject, IB)
end;
IA = interface
['{CDDE945F-BD5C-49B4-AF21-945460782C62}']
procedure A;
end;
IB = interface(IA)
['{BE689474-2621-4BB0-BB1B-F77E6D557560}']
procedure B;
end;
TA = class(TInterfacedObject, IA)
procedure A;
end;
TB = class(TA, IB)
procedure B;
end;

...{ TB }
procedure TB.B;
begin
end;

...{ TA }
procedure TA.A;
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a: IA;
b: IB;
begin
b := TB.Create;
ShowMessage(IntToStr(Integer(b)));
a := IA(b);
ShowMessage(IntToStr(Integer(a)));
a := b as IA;
ShowMessage(IntToStr(Integer(a)));
end;Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1412418
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。