Re: How does Cocoa implement delegate/callback?
Re: How does Cocoa implement delegate/callback?
- Subject: Re: How does Cocoa implement delegate/callback?
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 15 Nov 2002 05:13:48 -0500
on 02-11-14 12:41 PM, Bill Cheeseman at email@hidden wrote:
>
There are many Cocoa methods and functions, like NSBeginAlertSheet, that
>
give the user an option to pass a temporary delegate and a callback
>
selector. How does Cocoa implement this?
I want to thank the people who responded both privately and on the list.
I figured out the final piece of the puzzle overnight. I am wrapping an
Apple C API that requires me to register a C function as the callback, but I
want my clients to be able to register an Objective-C method. In my case,
the C API caches an unlimited number of callbacks, playing back different
callbacks depending on a variety of events.
The trick is to use the C API's registration mechanism as the cache for my
invocation objects. I create an invocation object when the client registers
its Objective-C callback method, then I register the required C callback
function in my own code, with my invocation object in its refcon parameter.
I cache the user's original refcon info in the invocation object. When Cocoa
calls my C callback function, the function fires the invocation object back
at the client, including the client's original refcon info. That way I don't
have to cache anything myself.
The C API gives me enough info that it's easy for my C callback function to
know where to send it.
Now I'll just have to see whether I can make it work.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.