VB.NET中回调函数如何使用

VB.NET中回调函数如何使用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

VB.NET经过长时间的发展,很多用户都很了解VB.NET回调函数了,这里我发表一下个人理解,和大家讨论讨论。创建数据库事件处理函数(VB.NET回调函数)

无论什么时候一个对象被打开并要被修改时,数据库事件处理函数会被调用。当然,如果这时我们监视的命令不是活动的,我们就应该跳过任何被这个VB.NET回调函数调用的内容。

If bEditCommand = False Then
Return
End If

同样地,如果我们监视的命令已经结束,而ObjectOpenedForModify事件被另一个VB.NET回调函数再次触发的话,而这时有对象被修改时,我们要阻止所有由这个VB.NET回调函数执行的动作。

If bDoRepositioning = True Then
Return
End If

这个VB.NET回调函数剩余部分的代码用来验证我们是否正在处理EMPLOYEE块索引。如果是的话,我们就获取它的ObjectID和位置(三维点)。下面的代码可以被粘贴到这个事件处理函数函数。

Public Sub objOpenedForMod(ByVal o As Object, ByVal e As ObjectEventArgs)  If bEditCommand = False Then  Return  End If  If bDoRepositioning = True Then  Return  End If  Dim objId As ObjectId  objId = e.DBObject.ObjectId  Dim trans As Transaction  Dim bt As BlockTable  Dim db As Database  db = HostApplicationServices.WorkingDatabase  trans = db.TransactionManager.StartTransaction()  Try  'Use it to open the current object!  Dim ent As Entity = trans.GetObject(objId, OpenMode.ForRead, False)  If TypeOf ent Is BlockReference Then 'We use .NET's RTTI to establish type.  Dim br As BlockReference = CType(ent, BlockReference)  'Test whether it is an employee block  'open its extension dictionary  If br.ExtensionDictionary().IsValid Then  Dim brExtDict As DBDictionary = trans.GetObject(br.ExtensionDictionary(), OpenMode.ForRead)  If brExtDict.GetAt("EmployeeData").IsValid Then  'successfully got "EmployeeData" so br is employee block ref  'Store the objectID and the position  changedObjects.Add(objId)  employeePositions.Add(br.Position)  'Get the attribute references,if any  Dim atts As AttributeCollection  atts = br.AttributeCollection  If atts.Count > 0 Then  Dim attId As ObjectId  For Each attId In atts  Dim att As AttributeReference  att = trans.GetObject(attId, OpenMode.ForRead, False)  changedObjects.Add(attId)  employeePositions.Add(att.Position)  Next  End If  End If  End If  End If  trans.Commit()  Finally  trans.Dispose()  End Try  End Sub

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对亿速云的支持。