All Manuals > CAPI User Guide and Reference Manual > 2 Getting Started

2.3 Linking code into CAPI elements

Getting a CAPI element to perform an action is done by specifying a callback. This is a function which is performed whenever you change the state of a CAPI element. It calls a piece of code whenever a choice is made in a window.

Note that the result of the callback function is ignored, and that its usefulness is in its side-effects.

  1. Try the following:
    (setq push-button
          (make-instance 'push-button
                         :data "Hello" 
                         #'(lambda (&rest args) 
                              "Hello World"))))
    (contain push-button)

    Specifying a callback

  2. Click on the Hello button.

    A dialog appears containing the message "Hello World".

    A dialog displayed by a callback.

    The CAPI provides the function display-message to allow you to pop up a dialog sheet containing a message and a Confirm button. This is one of many pre-defined facilities that the CAPI offers. You can also pop up a dialog window rather than a sheet, using prompt-with-message.

Note: When you develop CAPI applications, your application windows are run in the same Window system event loop as the LispWorks IDE. This - and the fact that in Common Lisp user code exists in the same global namespace as the Common Lisp implementation - means that a CAPI application running in the LispWorks IDE can modify the same values as you can concurrently modify from one of the the LispWorks IDE programming tools.

For example, your CAPI application might have a button that, when pressed, sets a slot in a particular object that you could also set by hand in the Listener. Such introspection can be useful but can also lead to unexpected values and behavior while testing your application code.

CAPI User Guide and Reference Manual (Macintosh version) - 01 Dec 2021 19:31:16