为什么我会收到错误的缺少实现? [英] Why do I get error Missing implementation?

查看:87
本文介绍了为什么我会收到错误的缺少实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误:

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

[DCC Error] Test.pas(10): E2291 Missing implementation of interface method ICoTest64.MyFunc

下面是TLB文件中的代码段.

Below is a snippet from the TLB file.

// *********************************************************************//
// 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

I'm using Delphi XE2

怎么了?

推荐答案

MyFunc 的功能参数列表不匹配.接口 ICoTest64 中的声明使用 const 参数.但是,您在类 TCoReporting64 中的实现使用了 var 参数.

The function parameter lists for MyFunc do not match. The declaration in the interface ICoTest64 uses a const parameter. But your implementation in the class TCoReporting64 uses a var parameter.

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

Assuming that the interface declaration is correct, you need to change your code thus:

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

这篇关于为什么我会收到错误的缺少实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆