开发者

how to use Option Strict On and Late Binding

I am trying to get some code to compile after switching Option Strict On. However I am usin开发者_开发百科g 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜