OnCreate event

1975
3
07-08-2010 09:08 AM
GregRieck
Occasional Contributor III
Hello,

Does anyone have any suggestions on why IObjectClassEvents.OnCreate is not being caught by an SDE database?

The same code works fine for a PGDB, yet fails when tried against an SDE SQL database. I have also implemented IObjectClassInfo and verified my DLL's are registered and present using Categories.exe. However, IEditEvents.OnCreateFeature is captured in both a PGDB and SDE. Is there any harm in having both events active and passing IObject from IEditEvents.OnCreateFeature to IObjectClassEvents.OnCreate?

G
0 Kudos
3 Replies
AlagappanAL
New Contributor II
Hi,

After creating the extension, the following are the steps to get fire OnCreate event

1. Registering the extension (Hope you have registered)
2. Applying the extension (This is very important to get fire OnCreate/OnChange and OnDelete events)

                  To apply an extension to an existing class, obtain an exclusive schema lock, then call the IClassSchemaEdit.AlterClassExtensionCLSID method. This method can also be used to remove a class extension by providing null values as both parameters. See the following code example:


'Pass the objectclass(featureclass) for which the extension to be applied (for which the
'oncreate event to get fired on creation of features) and the class id of the class extension file
'you created and set nothing for third parameter

Public Sub ChangeClassExtension(ByVal objectClass As IObjectClass, ByVal extensionUID As String, ByVal extensionProperties As IPropertySet)
    Dim schemaLock As ISchemaLock = CType(objectClass, ISchemaLock)
    Try
    ' Attempt to get an exclusive schema lock.
    schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock)
   
    ' Cast the object class to the IClassSchemaEdit2 interface.
    Dim classSchemaEdit As IClassSchemaEdit = CType(objectClass, IClassSchemaEdit)
    If Not extensionUID.Equals("") Then
        ' Create a unique identifier (UID) object and change the extension.
        Dim extUID As UID = New UIDClass()
        extUID.Value = extensionUID
        classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties)
    Else
        ' Clear the class extension.
        classSchemaEdit.AlterClassExtensionCLSID(Nothing, Nothing)
    End If
    Catch comExc As COMException
    Throw New Exception("Could not change class extension.", comExc)
    Finally
    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock)
    End Try
End Sub

Hope this helps you

Regards
Alagappan
0 Kudos
GregRieck
Occasional Contributor III
Alagappan,

Good call, that was it. I had totally forgotten about the "Applying" the extension part. I already had code to do that, just wasn't calling it. I add a call to the OnStartEditing event to register the extension and it is working as expected now. I had actually imported the database into an SQL database using the export/import XML tool. I guess I wasn't expecting to have to register the register my extensions with the schema. Makes sense now that I think it through more.

I must of disabled it because of some error it was causing. Is applying the extension something that can be called all of the time? Is there a better approach for making sure your custom extensions are registered with the schema?

Greg
0 Kudos
AlagappanAL
New Contributor II
Hi,

Applying class extension is a one time process. Once it is applied, it will be with that featureclass until the extension is removed (Removing extension is by passing nothing to the parameter in my previous code.)

If you registered the class extension and not applied, then the business needs (eg. update certain fields on oncreate) are not going to work. In this way, you can figure out whether the extension is applied or not

One more interesting thing: On applying class extension, the class id of the objectclass along with flower braces ({585b26b8-1598-43af-a167-02a2b22753c7}) will get stored in the EXTCLSID column of the respective object class in the system table �??GDB_OBJECTCLASSES�?�. This table cannot be viewed in ArcCatalog as it is the in-built system table but can be seen in SQL Server/Server Explorer. It is strongly recommended to use ArcObject classes to apply class extension instead of directly storing the classid in the system table.

Regards
Alagappan
0 Kudos