以下代码在对象的oDataObject.lastError
和oDataObject.clearerror()
处导致错误,而将option strict On
设置为一个后期绑定问题仍然存在。
在option strict
设置为on
之前,oDataObject.lastError
和oDataObject.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