本文介绍了将早期绑定代码转换为后期绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在VBA和VB6中编写早期绑定代码以使Office应用程序(Word,Excel等)自动化,然后将其切换为后期绑定以处理这些应用程序的多个版本.我正在尝试做同样的事情,但是我正在自动化ESRI ArcMap GIS应用程序,而我过去使用的概念似乎并没有翻译.

I've often written early-binding code in VBA and VB6 to automate office applications (Word, Excel, etc) then switched it to late-binding to handle multiple versions of those applications. I'm trying to do the same thing but I am automating an ESRI ArcMap GIS application and the concepts I've used in the past do not seem to be translating.

以下代码正确运行:

Sub EarlyBinding()
Dim ArcMap As esriArcMapUI.MxDocument

    Set ArcMap = GetObject("C:\Users\Mike\Downloads\Assessment Mapping.mxd", _
                           "esriArcMapUI.MxDocument")
    Debug.Print ArcMap.Title
End Sub


但是此代码失败,并且 Debug.Print行上的对象不支持此属性或方法:


But this code fails with Object doesn't support this property or method on the Debug.Print line:

Sub LateBinding()
Dim ArcMap As Object

    Set ArcMap = GetObject("C:\Users\Mike\Downloads\Assessment Mapping.mxd", _
                           "esriArcMapUI.MxDocument")
    Debug.Print ArcMap.Title

End Sub

与一般的COM服务器相比,它们对MS Office应用程序是否有特殊之处,它们比Windows服务器更好地支持此方法?还是他们不支持这种方法的ESRI应用程序的特殊之处?

Is there something special about MS Office apps that they support this approach better than COM servers in general? Or something special about ESRI apps that they do not support this approach?

推荐答案

Esri对象很可能没有正确支持IDISPATCH.您可能会尝试使用CALLBYNAME,但是我猜想它也不起作用,因为我相信它也可以通过IDispatch进行引导.

It's most likely that the Esri object isn't supporting IDISPATCH properly. You might try CALLBYNAME, but I'm guessing that won't work either because I believe it vectors through IDispatch as well.

这篇关于将早期绑定代码转换为后期绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 15:20