TComponent继承类如何自己实现IDispatch接口 (300分)

  • 主题发起人 主题发起人 qdyoung
  • 开始时间 开始时间
Q

qdyoung

Unregistered / Unconfirmed
GUEST, unregistred user!
TRemoteDataModule 的继承关系:
TRemoteDataModule = class(TDataModule, IAppServer)
IAppServer = interface(IDispatch)
IDispatch = interface(IUnknown)
IUnknown = IInterface;
TDataModule = class(TComponent)
TComponent = class(TPersistent, IInterface, IInterfaceComponentReference)
可见 TRemoteDataModule 实现了 IDispatch接口,但是IDispatch接口实现只在TComponent(classes.pas)中找到:
private
{ IDispatch }
function GetTypeInfoCount(out Count: Integer): HResult;
stdcall;
function GetTypeInfo(Index, LocaleID: Integer;
out TypeInfo): HResult;
stdcall;
function GetIDsOfNames(const IID: TGUID;
Names: Pointer;
NameCount, LocaleID: Integer;
DispIDs: Pointer): HResult;
stdcall;
function Invoke(DispID: Integer;
const IID: TGUID;
LocaleID: Integer;
Flags: Word;
var Params;
VarResult, ExcepInfo, ArgErr: Pointer): HResult;
stdcall;
跟踪发现其代码并没有被执行。那 TRemoteDataModule 的 IDispatch 接口是在哪里实现的呢?
在Delphi中找到自己实现IDispatch的地方,WebSnap用的TObjectDispatch(ObjComAuto)就是:
TObjectDispatch = class(TInterfacedObject, IDispatch)
private
FInstance: TObject;
FOwned: Boolean;
public
{ IDispatch }
function GetIDsOfNames(const IID: TGUID;
Names: Pointer;
NameCount: Integer;
LocaleID: Integer;
DispIDs: Pointer): HRESULT;
virtual;
stdcall;
function GetTypeInfo(Index: Integer;
LocaleID: Integer;
out TypeInfo): HRESULT;
stdcall;
function GetTypeInfoCount(out Count: Integer): HRESULT;
stdcall;
function Invoke(DispID: Integer;
const IID: TGUID;
LocaleID: Integer;
Flags: Word;
var Params;
VarResult: Pointer;
ExcepInfo: Pointer;
ArgErr: Pointer): HRESULT;
virtual;
stdcall;
public
constructor Create(Instance: TObject;
Owned: Boolean = True);
destructor Destroy;
override;
end;

TComponent继承类如何自己实现IDispatch接口呢?
已试过以下方法,不行,GetIDsOfNames不会被调用
TTest = class(TRemoteDataModule, ITest, IDispatch)
...
{ IDispatch }
function GetIDsOfNames(const IID: TGUID;
Names: Pointer;
NameCount: Integer;
LocaleID: Integer;
DispIDs: Pointer): HRESULT;
virtual;
stdcall;
function GetTypeInfo(Index: Integer;
LocaleID: Integer;
out TypeInfo): HRESULT;
stdcall;
function GetTypeInfoCount(out Count: Integer): HRESULT;
stdcall;
function Invoke(DispID: Integer;
const IID: TGUID;
LocaleID: Integer;
Flags: Word;
var Params;
VarResult: Pointer;
ExcepInfo: Pointer;
ArgErr: Pointer): HRESULT;
virtual;
stdcall;
end;
 
学习学习
 
后退
顶部