Built-in variables: parentthis

The variable parentthis refers to the immediate parent object, this object is embedded inside.

Declaration

object parentthis

Discussion

An object is considered as being embedded, when it has been created visually in the Composer. For example, a Text view you have dragged-and-dropped into a GUI component is an embedded object. The surrounding GUI component, in turn, is considered as its parent object.

If this object is not embedded within another object but it has been created dynamically at the runtime by using the new operator, the parentthis variable contains the value null.

You can use the variable parentthis within expressions wherever an operand of object data type is allowed. Usually, you do it in order to test whether the current object has been embedded or created dynamically:

if ( parentthis != null ) trace "This object has been embedded in Composer"; else trace "This object has been created at the runtime by using the new operator";

You can also perform a cast on the parentthis object to a known class in order to test, whether the parent object is an instance of this class. Subsequently, if the cast succeed, you can easily access the members of the parent object. This, for example, allows the embedded object to register itself by the parent as a target for notifications, etc. Following example is a code fragment from the Mosaic framework demonstrating how a key press handler object registers itself by a GUI component in order to listen to the received keyboard events:

var Core::Group group = (Core::Group)parentthis; // Insert the kandler into the list of keyhandlers of the parent if ( group != null ) { next = group.keyHandlers; group.keyHandlers = this; }