Re: Trouble with "self" in Carbon and Cocoa
Re: Trouble with "self" in Carbon and Cocoa
- Subject: Re: Trouble with "self" in Carbon and Cocoa
- From: j o a r <email@hidden>
- Date: Sat, 22 Mar 2003 11:39:31 +0100
You can only refere to self in Cocoa methods. Plain C functions doesn't
know which object they belong to, and so cannot reference self. You
would usually pass the reference to the object that you would like to
work with in the function as a parameter to that function.
In the case of a callback, you often have the ability to pass along a
void pointer when you setup the callback, this could perhaps be the
reference to your object?
j o a r
On Saturday, Mar 22, 2003, at 11:23 Europe/Stockholm, Jeffrey Mattox
wrote:
I have a hotkey handler that needs to call a method using "self" but
it causes a compile error. Elsewhere in my program I'm using "self"
without error. The hotkey handler is a C routine because that's what
I need in order to register it as the handler. Here's the outline:
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
@implementation NSApplication (mainline)
OSStatus HotKeyHandler(...)
{
[anObject aMethod]; // works for Foundation, et al
[self myCocoaMethod:YES]; // <--- causes "self" undeclared error
{
-(void) myCocoaMethod:(BOOL)flag
{
// never get here
}
@end
As a workaround, I can make it work by saving the value of "self" in
another variable during initialization and use that later in my
handler. E.g,:
NSApplication *mySelf;
...
{
...
mySelf = self;
}
I want to understand why the compiler is complaining. What must I to
do to get "self" to work in HotKeyHandler()?
_______________________________________________
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.