11.2.2 Manipulation operations
126.96.36.199 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.
- This returns
t, so, buttons are enabled by default. The next step is to destructively modify
button1 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
capi 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
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
- 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
This now returns
nil, 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, the
background slot of button objects is
nil. This example shows you how to modify the
button1 so that it is red.
- 13. Type the following into the listener and then press Return:
- 14. Choose Values > Copy in the listener to copy the symbol to the clipboard.
- 15. Select the
BACKGROUND slot of
button1 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 the
background slot of
- This sets the
background slot of
- 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:
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 the
enabled 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