• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble with "self" in Carbon and Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble with "self" in Carbon and Cocoa


  • Subject: Re: Trouble with "self" in Carbon and Cocoa
  • From: Bill Cheeseman <email@hidden>
  • Date: Sat, 22 Mar 2003 06:23:52 -0500

on 03-03-22 6:09 AM, Dix Lorenz at email@hidden wrote:

>> I want to understand why the compiler is complaining.
>
> You pretty much said it yourself: HotKeyHandler is a C-routine. It
> doesn't matter that it is inside an @implementation-block, it is not a
> method of your class. Would you expect it to know about "self" outside
> of this block? So there :-)
>
>> What must I to do to get "self" to work in HotKeyHandler()?
>
> Not knowing what HotKeyHandler really is: If it is a callback routine,
> they usually have a field where the user can stick some data, this
> would be the place to put a pointer to your object. If you just need
> the running NSApplication, use the global variable NSApp or
> [NSApplication sharedApplication]. In other cases your solution is
> probably ok, but that really depends on if you have more then one
> instance of the object. Then you need to have some way of determining
> which object to use and that could get messy or even impossible.

This is correct. Pass self (or whatever object, or even a dictionary full of
objects) in the userInfo parameter in the function that sets up the hot key,
then extract it and use it as self in the callback. I'm doing this myself in
a hot key handler, and it works like a charm.

This is a general principle, by the way. I use the same technique with other
callback functions in C APIs in the system frameworks.

--

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
_______________________________________________
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.

References: 
 >Re: Trouble with "self" in Carbon and Cocoa (From: Dix Lorenz <email@hidden>)

  • Prev by Date: Re: Trouble with "self" in Carbon and Cocoa
  • Next by Date: Window resize by blob, not by resize corner
  • Previous by thread: Re: Trouble with "self" in Carbon and Cocoa
  • Next by thread: Re: Trouble with "self" in Carbon and Cocoa
  • Index(es):
    • Date
    • Thread