On Nov 30, 2007, at 4:17 PM, Dave Addey wrote:
> I’m working on my RBScript-based controller code, and it’s all
> going well –
> but I have one more challenge....
>
> I’ve created a generic “Controller” class. The code for the
> controller is
> in an RBscript. I want to be able to register a callback, which
> will call a
> callback method on a controller class instance. I think this might
> be where
> I should use delegates?
>
> Historically, I’ve always had to use global module methods for
> callbacks.
> This has the downside that I don’t know (from within the callback)
> which
> controller object triggered the callback. Since my different
> controller
> types may need to use the same callback template (e.g. two UInt32
> params,
> returning a UInt32), I won’t even know which type of controller
> caused the
> callback, let alone which instance of the controller, in order to
> pass the
> callback event on to the controller for processing.
>
> I’m rather hoping that delegates give me a way to set up these
> callbacks
> using class-instance methods as the callback target. But I can’t
> work out
> what the code would be to do this. Do I need to define a delegate
> in a
> module? Do I need a property on the class to represent the
> callback method?
> Where would the callback code go?
First, you can also use shared methods for callbacks. But you cannot
use object methods as callbacks, by which I mean that you cannot pass
a pointer to an object method to something external. You'll need to
handle delegation of a callback to an object instance yourself;
fortunately, this is usually easy, especially if you get to pass some
user data that the callback includes.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|