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

问题描述

考虑以下代码:

uses
  {... }
  ComObj,
  ShlObj;

type
  TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
  private
  {(*}
  const
    GUID: TGUID = '{99D8B139-0855-4C5D-95E7-BC8EC6254B3D}';
  {*)}
  private
    FCmdCount: LongWord;
    FDm: Tdm_ContextMenu;
  protected
    function IShellExtInit.Initialize = IShellExtInit_Initialize;
    function IShellExtInit_Initialize(_pidlFolder: PItemIDList; _lpdobj: IDataObject;
      _HKeyProgID: HKEY): HResult; stdcall;
    function QueryContextMenu(_Menu: HMENU; _indexMenu, _idCmdFirst, _idCmdLast,
      _UFlags: UINT): HResult; stdcall;
    function InvokeCommand(var _ici: TCMInvokeCommandInfo): HResult; stdcall;
    function GetCommandString(_idCmd, _uType: UINT; _pwReserved: PUINT;
      _PszName: LPSTR; _cchMax: UINT): HResult; stdcall;
  public
    procedure Initialize; override;
    destructor Destroy; override;
  end;

这在Delphi 2007和XE中可以正常编译,但是Delphi XE2给了我错误:"[[DCC错误] u_ContextMenuHandler.pas(16):E2291缺少接口方法IContextMenu.GetCommandString的实现"

This compiles fine in Delphi 2007 and XE but Delphi XE2 gives me the error:"[DCC Error] u_ContextMenuHandler.pas(16): E2291 Missing implementation of interface method IContextMenu.GetCommandString"

这让我感到困惑.我检查了接口声明,并且我的GetCommandString函数具有与接口完全相同的声明.有提示吗?

This has me baffled. I checked the interface declaration and my GetCommandString function has the exactly the same declaration as the interface's. Any hints?

推荐答案

'_ idCmd'在XE2中声明为 UINT_PTR (目标为64位时为8字节).

'_idCmd' is declared UINT_PTR (which is 8 bytes when targeting 64-bit) in XE2.

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

07-25 07:11