Objects and Instances

Every object instance can be uniquely identified by a window id (also called instance handle). Slick-C® treats objects and windows the same. However, some objects, such as image control, have a window id but do not allocate an operating system resource known as a window.

Topics in this section are:

Active Object

When an object receives an event, that object is the active object. More specifically, the p_window_id property is set to the instance handle of that object. You can change the active object by setting the p_window_id property to the window id of another object. Accessing a property without specifying a control name or instance handle accesses the property of the active object and not the active form.

Note

Changing the active object does NOT change the focus. Use the _set_focus method to change the focus.

Active Form

Slick-C® has a p_active_form property that returns an instance handle to the current form. The Slick-C interpreter actually does not keep track of what form is active. The active form is found by traversing through the parents (p_parent) of the active object until the form is reached.

Instance Expressions

The examples below display common instance expressions.

ctltext1.p_text="test"; // Assuming ctltext1 has been declared globally or locally,
                        // lookup the ctltext1 control of the active form to get 
                        // the window id, and set the p_text property.
x=_control ctltext1;    // Put the window id of the "ctltext1" control of the active
                        // form in the variable x.
                        // The variable x does not have to be declared. There are
                        // cases where the control keyword is not needed. It is 
                        // better to always use it so you don't have to worry.
x.p_text="test";        // Set the p_text property of the object referenced by the
                        // instance expression x.
(x+1-1).p_text="test";  // Same as previous statement. This shows that any valid
                        // Slick-C language expression may be used to get the
                        // window id.
x.(x+1-1).x.p_text="test";
                        // Same as the previous statement but wastes more
                        // code space.
                        // This shows that multiple dots (".") may be used in an
                        // instance expression.
form_wid=p_active_form; // Get the window id of the active form.
form_wid.ctltext1.p_text="test";
                        // Lookup ctltext1 as if the object referred to by the
                        // variable form_wid was the active object.
p_next.p_next.p_prev.p_prev.p_text="test";
                        // Waste some code space and access the p_text property of
                        // the active object.
p_window_id=_control ctltext1;
                        // Make the ctltext1 control the active object.
p_text="test";          // Access the p_text property of the active object.
_cmdline.p_text="test"; // _cmdline is a constant window id defined in "slick.sh".
                        // Set the command line p_text property to "test". Cool!!