实例探讨VB.NET回调函数

开发 后端
这里介绍这个VB.NET回调函数剩余部分的代码用来验证我们是否正在处理EMPLOYEE块索引。如果是的话,我们就获取它的ObjectID和位置(三维点)。

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

#t#无论什么时候一个对象被打开并要被修改时,数据库事件处理函数会被调用。当然,如果这时我们监视的命令不是活动的,我们就应该跳过任何被这个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和位置(三维点)。下面的代码可以被粘贴到这个事件处理函数函数。

  1. Public Sub objOpenedForMod(ByVal o As Object, ByVal e As ObjectEventArgs)  
  2. If bEditCommand = False Then  
  3. Return  
  4. End If  
  5. If bDoRepositioning = True Then  
  6. Return  
  7. End If  
  8. Dim objId As ObjectId  
  9. objId = e.DBObject.ObjectId  
  10. Dim trans As Transaction  
  11. Dim bt As BlockTable  
  12. Dim db As Database  
  13. db = HostApplicationServices.WorkingDatabase  
  14. trans = db.TransactionManager.StartTransaction()  
  15. Try  
  16. 'Use it to open the current object!  
  17. Dim ent As Entity = trans.GetObject(objId, OpenMode.ForRead, False)  
  18. If TypeOf ent Is BlockReference Then 'We use .NET's RTTI to establish type.  
  19. Dim br As BlockReference = CType(ent, BlockReference)  
  20. 'Test whether it is an employee block  
  21. 'open its extension dictionary  
  22. If br.ExtensionDictionary().IsValid Then  
  23. Dim brExtDict As DBDictionary = trans.GetObject(br.ExtensionDictionary(), OpenMode.ForRead)  
  24. If brExtDict.GetAt("EmployeeData").IsValid Then  
  25. 'successfully got "EmployeeData" so br is employee block ref  
  26. 'Store the objectID and the position  
  27. changedObjects.Add(objId)  
  28. employeePositions.Add(br.Position)  
  29. 'Get the attribute references,if any  
  30. Dim atts As AttributeCollection  
  31. atts = br.AttributeCollection  
  32. If atts.Count > 0 Then  
  33. Dim attId As ObjectId  
  34. For Each attId In atts  
  35. Dim att As AttributeReference  
  36. att = trans.GetObject(attId, OpenMode.ForRead, False)  
  37. changedObjects.Add(attId)  
  38. employeePositions.Add(att.Position)  
  39. Next  
  40. End If  
  41. End If  
  42. End If  
  43. End If  
  44. trans.Commit()  
  45. Finally  
  46. trans.Dispose()  
  47. End Try  
  48. End Sub 
责任编辑:佚名 来源: IT168
相关推荐

2010-01-19 18:24:29

VB.NET调用Win

2009-10-19 17:42:31

VB.NET API函

2009-10-30 16:31:55

VB.NET重载方法

2009-10-15 17:50:48

VB.NET Spli

2009-10-28 14:13:32

VB.NET File

2009-10-28 14:34:44

VB.NET Tree

2009-10-21 10:45:50

VB.NET Quic

2009-10-26 16:53:00

VB.NET常用代码

2009-10-26 10:44:27

VB.NET API函

2010-01-18 10:33:28

VB.NET基本函数

2009-10-28 15:01:59

VB.NET SHEL

2009-11-02 13:14:18

VB.NET函数

2009-10-21 09:40:23

VB.NET搜索

2009-10-22 09:20:46

VB.NET Proc

2010-01-19 14:42:43

VB.NET调用过程重

2009-10-26 19:22:29

VB.NET使用Log

2010-01-21 14:27:46

VB.NET判断数组维

2009-10-14 09:15:15

2009-11-03 12:52:38

VB.NET Wind

2009-10-16 13:38:43

VB.NET Spli
点赞
收藏

51CTO技术栈公众号