在一个纯unit单元(UnitResource.pas)中写了一个从class和Interface继续下来的类.
TResource=Class(TObject, IPlugInBuilder)编译时报:
[Error] Undeclared identifier: 'QueryInterface'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_AddRef'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_Release'加了
function TResource._AddRef: Integer;
begin
result := -1;
end;function TResource._Release: Integer;
begin
result := -1;
end;function TResource.QueryInterface(const IID: TGUID; out Obj): HResult;
const
E_NOINTERFACE = $80004002;
begin
if GetInterface(IID, Obj) then
Result := 0
else
Result := -1; {E_NOINTERFACE}
end;
后, 又报下面三个错误,那更搞不懂了:
[Error] UnitResource.pas(73): Declaration of 'QueryInterface' differs from declaration in interface 'IInBuilder'
[Error] UnitResource.pas(73): Declaration of '_AddRef' differs from declaration in interface 'IInBuilder'
[Error] UnitResource.pas(73): Declaration of '_Release' differs from declaration in interface 'IInBuilder'
TResource=Class(TObject, IPlugInBuilder)编译时报:
[Error] Undeclared identifier: 'QueryInterface'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_AddRef'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_Release'加了
function TResource._AddRef: Integer;
begin
result := -1;
end;function TResource._Release: Integer;
begin
result := -1;
end;function TResource.QueryInterface(const IID: TGUID; out Obj): HResult;
const
E_NOINTERFACE = $80004002;
begin
if GetInterface(IID, Obj) then
Result := 0
else
Result := -1; {E_NOINTERFACE}
end;
后, 又报下面三个错误,那更搞不懂了:
[Error] UnitResource.pas(73): Declaration of 'QueryInterface' differs from declaration in interface 'IInBuilder'
[Error] UnitResource.pas(73): Declaration of '_AddRef' differs from declaration in interface 'IInBuilder'
[Error] UnitResource.pas(73): Declaration of '_Release' differs from declaration in interface 'IInBuilder'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_AddRef'
[Error] UnitPlugIn.pas(73): Undeclared identifier: '_Release'//////////////错误提示是“未经宣布的”说明你需要发布一下,或者声明一下什么的吧
改为:
TResource=Class(TInterfacedObject, IPlugInBuilder)
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;你掉了stdcall所以编译器报错,函数声明不一致