callback
A callback procedure to be executed before an identifier of type ident is deleted. This member is applicable to structure definitions only, i.e. class, structure, dbstructure, gstructure or compound. It is often referred to as a destructor.
When a destructor is invoked, the name of the structure object being deleted is passed to it as a parameter. It is up to the procedure to then decide if the object should be deleted (via the delid command) or not. The object will not be deleted automatically when a destructor is executed. Destructors should not be called explicitly.
The callback should always define its first parameter with an appropriate args statement (see the example below).
Destructors will only be invoked automatically for top-level objects, but not for objects which are children of parent structures. For such child objects, the destruction code must be executed explicitly within the parent destructor.
If a requirement is to call a destructor explicitly, it should only be invoked by the delid command. It must NOT be called by a statement such as ident.delete(object), nor by object.delete.
ident.delete (<structure>)
# Define a structure. class ~test.thing { string name numeric value } # Define a destructor for it. ~test.thing.delete = { args t = ~test.thing tell <'Thing (^(t.name)) is being deleted'> delid t } # Create an object of type ~test.thing. ~test.thing my_obj; my_obj.name = 'Simon' # Delete the object, thus invoking its destructor. delid my_obj
A destructor may be defined within a class definition command block. Consider this alternative to the above:
class ~test.thing { string name numeric value delete = { args t = ~test.thing tell <'Thing (^(t.name)) is being deleted'> delid t } }
Commands: |
|
Structures: |