ArcObjects Library Reference  (GeoDatabase)    

IObjectClassEvents Example

[Visual Basic 6.0]

It is important to note that there are two distinct methods of using the IObjectClassEvents interface.

One way is to implement a geodatabase-level customization by referencing IObjectClassEvents in a ClassExtension. An example of this and other ClassExtensions are available at the online developer support site. 

Another way is to use outbound interface (WithEvents) to listen for editing events outside the editor. In this following VBA example, changes made to a layer in ArcMap are trapped.

How to use:

  1. In ArcMap, paste the code into the ThisDocument code window.
  2. Run the initEvents() procedure
  3. Use the ArcMap Editor to make a change to a feature in the layer at the top of the table of contents.
Private WithEvents ObjectClassEvents As ObjectClassEvents

Public Sub initEvents()
  Dim pMxdoc As IMxDocument
  Set pMxdoc = Application.Document
  Dim pFeatureLayer As IFeatureLayer
  Dim pLayer As ILayer
  Dim pFeatureClass As IFeatureClass
  Set pLayer = pMxdoc.FocusMap.Layer(0)
  Set pFeatureLayer = pLayer
  Set pFeatureClass = pFeatureLayer.FeatureClass
  Dim pObjectClass As IObjectClass
  Set pObjectClass = pFeatureClass
  Set ObjectClassEvents = pObjectClass
End Sub

Private Sub ObjectClassEvents_OnChange(ByVal obj As IObject)
  MsgBox "OnChange for: " & obj.OID
End Sub

Private Sub ObjectClassEvents_OnCreate(ByVal obj As IObject)
  MsgBox "OnCreate for: " & obj.OID
End Sub

Private Sub ObjectClassEvents_OnDelete(ByVal obj As IObject)
  MsgBox "OnDelete for: " & obj.OID
End Sub


[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.