Next Prev Up Top Contents Index

13.3.4.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 button object to find out whether or not it is enabled:
  2. (defun button-enabled-p (capi:button)
                  (slot-value capi:button 'capi::enabled))
  3. Next, create a button as follows:
  4. (setq button1 (make-instance 'capi:button))
  5. Choose Values > Inspect in the listener to inspect the button in the inspector.
  6. In the listener, use the function you just defined to find out whether button1 is enabled.
  7. (button-enabled-p button1)

    This returns t , so, buttons are enabled by default. The next step is to destructively modify button1 so that it is not enabled.

  8. Choose Works > Tools > Preferences from the inspector's menu bar.
  9. The Inspector Preferences dialog appears, so that you can change the current package of the inspector.

  10. In the text box in the Package panel, replace the default package name with CAPI and click OK .
  11. This changes the process package of the inspector to the CAPI package, and the package name disappears from all the slots listed. This makes the display a lot easier to read.

  12. In the inspector, type enabled into the Filter box and press Return.
  13. 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.

  14. Select the slot enabled to t .
  15. Choose Slots > Set...
  16. A dialog appears into which you can type a new value for the slot enabled .

     

    Figure 13.5 Entering a new slot value

  17. Type nil in the dialog and click on OK .
  18. The Main area reflects the new value of ENABLED .

  19. Click on the
  20. button. This removes the filter and displays all the slots once again.
  21. To confirm that the change happened, type the following in the listener. (You should be able to recall the last command using Alt+P .)
  22. (button-enabled-p button1)

    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 background of button1 so that it is red.

  23. Type the following into the listener and then press Return:
  24. "Hello World!"
  25. Choose Values > Copy to copy the string to the clipboard.
  26. Select the TEXT slot of button1 in the inspector.
  27. Choose Slots > Paste to paste the "Hello World!" string into the text slot of button1 .
  28. This sets the text slot of button1 to the string.

    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:

  29. Choose Object > Listen .
  30. 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.

  31. In the listener, type the following:
(capi:contain *)

This displays a window containing the button object. Note that the text now reads "Hello World!", 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 Slots> Copy to copy this value to other objects in the inspector, or even to other tools.


Common LispWorks User Guide - 14 Dec 2001

Next Prev Up Top Contents Index