为什么我会收到错误实施错误?

时间:2013-08-28 16:15:50

标签: delphi delphi-xe2

我收到了一个错误:

  

[DCC错误] Test.pas(10):E2291缺少接口方法ICoTest64.MyFunc的实现

以下是TLB文件的摘录。

// *********************************************************************//
// Interface: ICoTest64
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {76CF78FE-22A3-4C0B-B1A9-97634A453AE3}
// *********************************************************************//
  ICoTest64 = interface(IDispatch)
    ['{76CF78FE-22A3-4C0B-B1A9-97634A453AE3}']
    function MyFunc(const Range: System.OleVariant): System.OleVariant; safecall;
  end;

这是实施

unit Test;

interface

uses
  SysUtils, ComObj, ComServ, ActiveX, Variants, Office2000, Excel2000, 
  adxAddIn, Test64_TLB,
  System.Classes, adxHostAppEvents, Dialogs, StdVcl;

type
  TCoTest64 = class(TadxAddin, ICoTest64)
  protected
    function MyFunc(var Range: System.OleVariant): System.OleVariant; safecall;
  end;

implementation

function TCoTest64.MyFunc(var Range: System.OleVariant): System.OleVariant;
begin
  Result:= 10;
end;

end.

据我所知implementation = interface

我正在使用Delphi XE2

怎么了?

1 个答案:

答案 0 :(得分:6)

MyFunc的函数参数列表不匹配。接口ICoTest64中的声明使用const参数。但是,您在班级TCoReporting64中的实施使用var参数。

假设接口声明正确,您需要更改代码:

type
  TCoReporting64 = class(TadxAddin, ICoTest64)
  protected
    function MyFunc(const Range: System.OleVariant): System.OleVariant; safecall;
  end;
相关问题