Special

Special Print Closeout!

We're clearing out the remainder of our print issues at fire sale prices -- as much as 75% off! Quantities are extremely limited and only available while supplies last. Hurry to take advantage of this one-time offer.

RBD Magazines

Once these printed back issues are gone, they are gone!

Article Preview


Buy Now

Print:
PDF:

Object-Oriented Thinking

Object-Oriented Callbacks

Issue: 2.3 (December/January 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 4,805
Starting Page Number: 36
RBD Number: 2316
Resource File(s): None
Related Web Link(s):

http://www.quantum-meruit.com/RB/WindowMenu.sit
http://www.quantum-meruit.com/RB/SortLibrary.sit
http://developer.apple.com/technotes/tn/tn2009.html

Known Limitations: None

Excerpt of article text...

A callback is a technique in which one passes a function pointer to another function or data structure; this function pointer can then be called at some later point in time. This bit of indirection is a standard trick in C programming. However, REALbasic doesn't support pointer programming. To see how to implement callbacks in REALbasic, let's take a look at some basic problems for which one might use a callback in C, introduce some new jargon, and explore how to solve these problems in REALbasic.

Notification

If you root around in the MacOS Carbon documentation, you'll see that you handle events using callbacks. That is, you write functions that handle events as appropriate and register them with the application, a window, or a control by passing a function pointer to a function like InstallEventHandler.

In general terms, the problem here is that when an event occurs, other objects would like to be notified so that they can do something. This is the Observer pattern. In REALbasic, you think in terms of objects notifying other objects of events, or changes of state. We'll need a way for objects to register their interest in the events of other objects, and a way for those objects to announce the occurrence of events.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com