Delphi Excel COM-Addin

我在Delphi 2006中写了一个MS Excel COM-Addin。我在我的开发机器上安装了Excel 2007。

我作为一个ActiveX库开始项目,然后从Delphi ActiveX项目菜单中添加一个自动化对象。

在我的自动化对象中,我定义了IDTExtensibility2接口

IDTExtensibility2 = interface(IDispatch) ['{32E456FC-C710-43AA-9ACA-DDE8F132B91B}'] function OnAddinsUpdate(var w_Custom: OleVariant): HResult; stdcall; function OnBeginShutDown(var w_Custom: OleVariant): HResult; stdcall; function OnConnection(const w_Application: IDispatch; w_ConnectMode: Integer; const w_AddInInst: IDispatch; var w_Custom: OleVariant): HResult; stdcall; function OnDisconnection(w_DisconnectMode: Integer; var w_Custom: OleVariant): HResult; stdcall; function OnStartupComplete(var w_Custom: OleVariant): HResult; stdcall; end; 

并在从TAutoObject派生的类中实现接口。

在我打电话的单位的初始化部分

 TAutoObjectFactory.Create(ComServer, TPBSExcelAddin, Class_PBSExcelAddin, ciSingleInstance, tmApartment); 

COM对象注册罚款,并显示在Excel加载项选项,但它会安装在Excel中。 我刚刚得到错误“未加载。COM加载过程中发生错误”

任何人都可以看到我的界面有问题吗? 或者我创buildCOM对象的方式? 有没有办法来debugging呢?

谢谢

你有你的IDTExtensibility2声明错误。 它应该是:

 IDTExtensibility2 = interface(IDispatch) ['{B65AD801-ABAF-11D0-BB8B-00A0C90F2744}'] procedure OnConnection(const Application: IDispatch; ConnectMode: ext_ConnectMode; const AddInInst: IDispatch; var custom: PSafeArray); safecall; procedure OnDisconnection(RemoveMode: ext_DisconnectMode; var custom: PSafeArray); safecall; procedure OnAddInsUpdate(var custom: PSafeArray); safecall; procedure OnStartupComplete(var custom: PSafeArray); safecall; procedure OnBeginShutdown(var custom: PSafeArray); safecall; end; 

需要记住的一件事是,接口中的方法必须以正确的顺序进行声明 – 您以错误的顺序声明它们。 我也不知道你从哪里得到你的GUID。

我通过导入Microsoft Add-In Designer的types库来获得此接口声明。 我强烈build议你也这样做。

是的,有一种方法来debugging这个:

  1. closuresExcel
  2. 打开你的项目选项(Ctrl + Shift + F11)
  3. 转到链接器选项卡
  4. 选中包括TD32debugging信息包含远程debugging符号 。 (也许只有第一个需要,但比抱歉更安全)
  5. 转到运行参数(运行菜单,参数…)
  6. 将主机应用程序更改为Excel
  7. 重新生成并运行,一旦你的插件被加载,你可以开始debugging。

当你从来没有进入debugging过程,这意味着问题可能不在你的初始化代码中,那么加载必要的软件包可能有问题,或者你的插件没有正确的实现_IDExtensibility接口。