realbasic-plugins
[Top] [All Lists]

Re: Callback functions

To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
Subject: Re: Callback functions
From: James Milne <james dot milne at mac dot com>
Date: Tue, 26 Oct 2004 13:58:22 +0100
Delivered-to: realbasic-plugins at lists dot realsoftware dot com
References: <1329EC4B-2495-11D9-814C-000A27B1C8AE at elfdata dot com> <6 dot 1 dot 0 dot 6 dot 2 dot 20041026074236 dot 06127ec0 at mail1 dot netreach dot net>

On 26 Oct, 2004, at 12:44, Leonard Rosenthol wrote:

Following up on some discussions of earlier about how to pass a "callback function" into a plugin, so that the plugin can call on the RB app as needed (progress, threading, etc.)

What is the best/approved/recommended method for doing this? Passing in an AddressOf? REALLoadObjectMethod()? Other?

This only needs to work on Mac OS X and Windows...

I'd advise against _all_ of the above. They are not type-safe, so it would be quite easy to
make your code crash. There are better ways to do this in RB.

Best idea is to either define an interface, or provide an event in one of your classes.

If you define an interface, simply provide an API where the user can attach an object which implements that interface to use as a callback. When you want to call the method, use REALInterfaceRoutine to resolve the function pointer for the method in the interface, then
call it.

If you use an event, you just need to add the event definition to your class's event table. When you want to call the event handler, you can resolve the event handler function pointer using REALGetEventInstance(), passing in the entry in the event table
you wish to resolve a function pointer for.

--
Kind Regards,
James Milne

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>