对象的后期绑定问题

时间:2018-09-07 09:50:38

标签: vb.net

以下代码在对象的oDataObject.lastErroroDataObject.clearerror()处导致错误,而将option strict On设置为一个后期绑定问题仍然存在。 在option strict设置为on之前,oDataObject.lastErroroDataObject.clearerror()显示为内置函数并支持所有类。

If Not trySettingValue(moProp, oDataObject, oTB.Text, sError) Then
        oTB.BackColor = System.Drawing.Color.Red
        bOk = False
Else
        oTB.BackColor = System.Drawing.Color.White
End If

 Public Shared Function trySettingValue(ByRef oProp As 
     System.Reflection.PropertyInfo, _
    ByRef oDataObject As Object, _
    ByVal oValue As Object, _
    ByRef sError As String) As Boolean
    Try
        oDataObject.clearerror()
        Select Case oProp.PropertyType.FullName

            Case "System.String"
                Dim str As String
                str = CType(oValue, String)
                oProp.SetValue(oDataObject, str, Nothing)
            Case Else
        End Select
        ' errorhandling  
        If oDataObject.lastError <> "" Then
            sError = sError & oDataObject.lastError
            Return False
        Else
            Return True
        End If
    Catch e As System.Exception
        Trace.WriteLine(e.Message)
        Trace.Flush()
        sError = sError & "De ingevoerde waarde voor '" & oProp.Name & "' is foutief." & vbCrLf
        Return False
    End Try
End Function

0 个答案:

没有答案