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

Joh*_*ica 0 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;
Run Code Online (Sandbox Code Playgroud)

这是实施

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.
Run Code Online (Sandbox Code Playgroud)

据我所知 implementation = interface

我正在使用Delphi XE2

怎么了?

Dav*_*nan 6

函数参数列表MyFunc不匹配.接口中的声明ICoTest64使用const参数.但是你在类中的实现TCoReporting64使用了一个var参数.

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

type
  TCoReporting64 = class(TadxAddin, ICoTest64)
  protected
    function MyFunc(const Range: System.OleVariant): System.OleVariant; safecall;
  end;
Run Code Online (Sandbox Code Playgroud)