obj_set_parent sets the parent object.
Return Value
bool is TRUE (1) if the function could set the parent successfully.
Parameters
obj is the object created with obj_create.
parent is an object created with obj_create.
Comment
The obj_set_parent function copies all key-value pairs from parent to obj and saves a reference of the parent object. obj “inherits” all properties of its parent.The child object will also inherit all parent methods. If obj.name(1,2) is invoked and P obj does not possess a method name, the parent function will be invoked obj.parent.name(1,2). If the parent does not possess a function a method name its parent object is invoked-Objekten obj.parent.parent.name(1,2) and so on.
Example
Create an object with one property with the name type. This object could be used as a base object for other objects:
def object_set_type(o, tp)
{
o["$type"] = tp;
}
def object_get_type(o)
{
return o["$type"];
}
def object_create(_type)
{
o = obj_create();
o["$type"] = _type;
f = obj_create();
f.__setprop__ = obj_create();
f.__setprop__.type = "object_set_type";
f.__getprop__ = obj_create();
f.__getprop__.type = "object_get_type";
o.set_methods(f);
return o;
}
def my_obj()
{
o = obj_create();
p = object_create("my_obj");
o.set_parent(p);
return o;
}
o = my_obj();
print o.type
See also
id-1665813