如何使用 Option Strict On 和 Late Binding
我试图在切换 Option Strict On 后编译一些代码。但是,我正在使用一些与 VB6 的互操作并传入表单对象 ByRef,因此 Form.Caption 失败,并且我无法将其转换为 Form 类型,因为 VB.NET 表单没有标题属性。
如何使用 Option Strict ON 进行以下编译:
Public Sub EditFormLegacy(ByRef objForm As Object)
objForm.Caption = objForm.Caption + " Edited"
End Sub
有没有办法为特定方法关闭 option strict?
I am trying to get some code to compile after switching Option Strict On. However I am using some Interop with VB6 and passing in a form object ByRef so Form.Caption fails and I can't convert it to type Form because a VB.NET Form doesn't have a caption property.
How can I can get the following to compile with Option Strict ON:
Public Sub EditFormLegacy(ByRef objForm As Object)
objForm.Caption = objForm.Caption + " Edited"
End Sub
Is there any way to switch option strict off for specific methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法为方法关闭它,但可以为窗体或类关闭它。只需将“选项严格关闭”放在表格顶部即可。根据 MSDN - “如果使用,Option Strict 语句必须出现在文件中任何其他源代码语句之前。”华泰
You can't turn it off for a method, but you can turn if off for a form or class. Just put "option strict off" at the top of the form. Per MSDN - "If used, the Option Strict statement must appear in a file before any other source code statements." HTH
您确实想要保留“严格”选项,所以我想您应该尝试一种解决方法。例如,获取表单(带有标题)以将其标题存储在单独的字符串中,该字符串可以通过表单中加载的新类来调用。
You really want to leave option Strict on, so I guess you should try a workaround. For example, get the form (with the caption) to store it's Caption in a seperate string, which can be recalled by the new class loading in the form.