就拿TComponent来说吧。
TComponent = class(TPersistent, IInterface, IInterfaceComponentReference)
......
function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
......//其它部分不写了。
end;
而在system.pas中:
type
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;//
不明白在TComponent中为什么还要再声明一遍???不是已经继承了该接口了么?
TComponent = class(TPersistent, IInterface, IInterfaceComponentReference)
......
function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
......//其它部分不写了。
end;
而在system.pas中:
type
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;//
不明白在TComponent中为什么还要再声明一遍???不是已经继承了该接口了么?
是说
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
三个方法吗。
TComponent中可不是声明呢,它是要实现这三个方法。
接口声明的方法,要在实现该接口的类中实现。
看不见实现代码,只是声明TComponent
在这里实现