11.2.2 Manipulation operations
11.2.2.1 Example
This example takes you through the process of creating an object, examining its contents, and then modifying the object.
- 1. In a listener, define the following function, which examines the contents of an
eagle
object to find out whether or not it is golden:
(defun enabled-p (capi:button)
(slot-value capi:button 'capi::enabled))
- 2. Next, create an eagle as follows:
(setq button1 (make-instance 'capi:button)
- 3. Choose Values > Inspect in the listener to copy the button to the inspector.
- 4. In the listener, use the function you just defined to find out whether
button1
is enabled.
(enabled-p button1)
- This returns
t
, so, buttons are enabled by default. The next step is to destructively modifybutton1
so that it is not enabled.
- 5. Choose View > Package in the inspector.
- A dialog appears so that you can change the current package of the inspector.
- 6. Delete the string
USER
, typecapi
and click OK.
- This changes the package of the inspector to the CAPI package, and the package name disappears from all the slots listed in the Main area. This makes the display a lot easier to read.
- 7. In the inspector, type
enabled
into the Filter area and press Return.
- Button objects have a large number of slots, and so it is easier to filter out the slots that you do not want to see than to search through the whole list. After applying the filter, only one slot is listed in the Main area.
- 8. Select the slot
ENABLED T
in the Main area.
- 9. Choose Slots > Set.
- A dialog appears into which you can type a new value for the slot
enabled
.
Figure 11.6 Entering a new slot value
- 10. Type
nil
in the dialog and click on OK.
- The Main area reflects the new value of
ENABLED
.
- 11. Delete the string
enabled
in the Filter area and press Return. This removes the filter and displays all the slots once again.
- 12. To confirm that the change happened, type the following in the listener. (You should be able to recall the last command using
Meta-P
.)
(enabled-p button1)
This now returnsnil
, as expected. The next part of this example shows you how you can modify the slots of an object by pasting in the contents of the clipboard. By default, thebackground
slot of button objects isnil
. This example shows you how to modify thebackground
ofbutton1
so that it is red.
- 13. Type the following into the listener and then press Return:
:red
- 14. Choose Values > Copy in the listener to copy the symbol to the clipboard.
- 15. Select the
BACKGROUND
slot ofbutton1
in the inspector.
- You may have to delete the string
enabled
in the Filter area in order to see this slot.
- 16. Choose Slots > Paste in the inspector to paste the
:red
symbol into thebackground
slot ofbutton1
.
- This sets the
background
slot ofbutton1
to:red
.
- You can confirm the effect of this change by displaying the button object. To do this, transfer it back into the listener and display it as follows:
- 17. Choose Object > Listen in the inspector.
- This transfers the button object back into the listener. As feedback, the string representation of the object is printed in the listener above the current prompt. The object is automatically transferred to the
*
variable so that it can be operated on.
- 18. In the listener, type the following:
(capi:contain *)
This displays a window containing the button object. Note that it has a red background, as you would expect. Note further that you cannot click on the button; it is not enabled. This is because you modified the setting of theenabled
slot in the earlier part of this example. You can also use Items > Copy to copy this value to other objects in the inspector, or even to other tools.
Common LispWorks User Guide, Liquid Common Lisp Version 5.0 - 18 OCT 1996 Generated with Harlequin WebMaker