【问题标题】:Option Strict On disallows late binding in vb.netOption Strict On 不允许在 vb.net 中进行后期绑定
【发布时间】:2019-06-01 22:12:36
【问题描述】:

我正在使用第 3 部分程序的 COM 接口来获取有关我的功能的信息。 (VS2017 和框架 4.7.2)。

我收到来自 Visual Studio 的错误:以下函数的“Option Strict On 不允许后期绑定”

'x, y, z, al, be, ga. as an array 
Protected Friend Shared Function GetComputedBRFPos(ByVal bodyElement As IScrBody, ByVal index As Integer) As Array
    Return bodyElement.getComputedBRFPos(p_index:=index)
End Function

它在第 3 部分工具中有一个文档,我也在编写描述。

VARIANTList getComputedBRFPos ()
获取当前 BRF 位置,如果不存在求解器,则创建一个隐式求解器。数组元素:x、y、z、al、be、ga。

举个例子,我正在使用另一个正在使用的函数,但下面的函数没有后期绑定错误。

Protected Friend Shared Function Get_sb_node_pos(ByVal bodyElement As IScrBody, ByVal childIndex As Integer) As Array
    Return bodyElement.get_sb_node_pos(p_childIndex:=childIndex)
End Function

这是文档中的描述。

VARIANTList get_sb_node_pos (int childIndex)
获取所有元素 sb_node_pos 作为一个数组。

我认为它会导致 bodyElement.getComputedBRFPos(p_index:=index) "index" 值,但我不知道确切的问题是什么以及如何实现。

【问题讨论】:

  • 我认为这是因为除非显式强制转换,否则您无法将数组的内容拆箱。基本上,编译器在返回数组之前并不知道数组里面有什么。
  • @AlessandroMandelli 是的,也许是因为我得到了一个数组列表,但没有在函数处定义索引,然后像 bodyElement.getComputedBRFPos() 一样使用,之后就不可能了主函数如 GetComputedBRFPos(Body)(i) ?
  • 你可能需要指定数组的类型——如果你返回一个包含字符串的数组,我认为你的函数声明的结尾应该——不要引用我的话,比如Friend Shared Function (your parameters here) As String()而不是简单的As Array

标签: vb.net late-binding


【解决方案1】:

从您发布的文档看来, bodyElement.getComputedBRFPos 似乎没有任何参数。在 VB.NET 中,() 对于没有参数的方法是可选的。所以你的代码最终看起来像这样。

Return bodyElement.getComputedBRFPos()(p_index:=index)

它不返回一个数组,而是返回数组的一个元素,它是对象类型的。

您应该删除参数、更改返回类型或向我们展示带有您尝试调用的参数的方法的文档。

Return bodyElement.getComputedBRFPos()

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多