Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
before delete instance
Answer
1/9/19 1:49 PM
Dear ADOxx-Team,

I try to delete all directly connected instances before an instance is deleted. Therefore I use the event BeforeDeleteInstance but it seems that the connectors and the instance are already deleted before the event is fired. So I can’t get the endpoints of the connectors and delete them before the actually instance is deleted.

I run this code and the returned objids in line 5 is empty although there should be connectors.

1ON_EVENT "BeforeDeleteInstance" {
2#The parameter instid provides the ID of the deleted instance, classid the class of the instance and modelid the ID of the affected model.
3SETL gelöschtesObjektClassid:(classid)
4SETL modelidVonGelöschtenObjekt:(modelid)
5CC "Core" GET_CONNECTORS objid:(instid) out
6CC "AdoScript" INFOBOX ("objekte " + (objids) + ", instance " + STR(instid))
7}

Which event would be the right one for my problem?

RE: before delete instance
Answer
6/13/14 9:02 AM as a reply to Tamara Gurschler.
Dear Tamara,

Your observation is right with respect to the "BeforeDeleteInstance" event in ADOxx. The CONNECTORS are discarded before the event actually fires. In order to realize your scenario we would propose the following implementation approach:

1. Additional attribute of Type EXPRESSION in (all) classes that can be used as SOURCE instances for relations
This attribute takes care to store automatically all connected instance IDs within the SOURCE instance. The attribute must not be made visible to the user (excluded from AttrRep)

Attributename: ConnectedObjs
1EXPR type:string expr:fixed: (ctobjs("hat"))

HINT: in the example above, the EXPRESSION only considers the "hat" relation class. Multiple relation classes can be combined using the tokunion() to combine tokens.

2. Update des EVENT AdoScript
For simplicity reasons, the fragment below only choose the logic proposed to delete connected objects.
 1ON_EVENT "BeforeDeleteInstance" {
 2  #...
 3  # Before delete, read the value of the StringToken in ConnectedObjs
 4  CC "Core" debug GET_ATTR_VAL objid: (instid) attrname"ConnectedObjs")
 5  # Check whether the attribute exists and only continue if it exisits.
 6  IF (ecode = 0) {
 7    SETL ltObjIDsval)
 8    # Delete connected objects - TODO: Filter target classes by classid/type, "stObjID" within the loop can be used to retrieve properties of the instance.
 9    FOR stObjID inltObjIDs) {
10      # implicit recursion of event - DELETE_OBJ triggers another "BeforeDeleteInstance" - TODO check on self-referencing instances
11      CC "Core" DELETE_OBJ modelid: (modelid) objid: (VAL stObjID)
12    }
13  }
14}