Element: ident.create { }

Type

callback

Description

A callback procedure to be executed after an identifier of type ident has been created. This member is applicable to structure definitions only, i.e. class, structure, dbstructure, gstructure or compound. It is often referred to as a constructor.

Constructors will only be invoked automatically for top-level objects, but not for objects which are children of parent structures. Constructors should not be called explicitly.

When a constructor is invoked, the name of the structure object being created is passed to it as a parameter. The callback should therefore always define this parameter with an appropriate args statement (see the examples below).

Parameters

ident.create (<structure>{,<args>, .... })

Examples

# Define a structure.
atable test
class ~test.thing {
    string name
    numeric value
}
 
# Define a constructor for it.
~test.thing.create = {
# The first parameter must be the identifier being created.
    args t = ~test.thing
    t.name = 'unknown'
	t.value = -1
}
 
# Create an object of type ~test.thing.
~test.thing my_obj
# ~test.thing.create is now called automatically.
tell <my_obj.name, my_obj.value>
# ... will print: unknown -1.

Other user-parameters may be passed to a constructor, and the constructor may be defined within a class definition command block.

class ~test.thing {
    string name
    numeric value
    create = {
    # The first parameter must be the identifier being created
       args t = ~test.thing
       args n = string;# User parameter
       args v = numeric;# User parameter
       if (n) t.name = n
       else t.name = 'unknown'
       if (v) t.value = v
       else t.value = -1
    }
}
 
# Objects of type ~test.thing may now be created thus:
~test.thing my_obj_1
~test.thing my_obj_2('Simon')
~test.thing my_obj_3('Simon',44.7)

See Also

Commands:

class

Structures:

*.delete