Anyone know carbon event handling?

Posted:
in Genius Bar edited January 2014
I've been having a great annoynace trying to implement event handling, can anyone shed light?



The problem is when installing event handlers, on this function:



NewEventLoopTimerUPP((EventLoopTimerProcPtr)eventF unction);



which creates the event loop timer



My problem is that eventFunction() is not working, it is a function in the class that is handling/installing my events. It works if I put it outside the class, but not if it is a public or private function inside, and I sort of need it inside the class.



The error I get is: myClass.cpp:40: no matches converting function `eventFunction' to type `void (*)(struct __EventLoopTimer*, void*)'



Anyone?

Comments

  • Reply 1 of 1
    i've encountered a similar problem, and here's how i understood it: the func "NewEventLoopTimerUPP" i'll assume takes a function as a parameter. functions cna be treated as pointers, but MEMBER functions (of classes/objects) don't always behave as advertised. first off, in c++, there is an implicit paramater ( "this" ), which (usually) precedes the other parameters. so, assuming ur eventFunction has the right footmark to fill in NewEvenLoopTimerUPP, u can't really take into account the "this" parameter of a member function. u could have NewEventLoopTimerUPP access a static member function of ur class(es), but that would probably negate the benefits of the class [static member functions aren't passed any "this" parameter, and aren't associated iwth a particular instance of an object]. u might try this: keep a global pointer (of ur class type) called something like "currentObject" and point it at the most recent object which is likely to get the next event. then, when New...UPP hits ur static member function, it can check if currentObject is valid (non-zero) and then throw the event at it.



    but aside from the complicatedness i described above, there is no elegant way to get at the class (assuming u need to get at a particular instance of a class).



    also, i should admit that i haven't worked very much with carbon or its event model. i went from classic right to cocoa; skipping the middle-man. and i haven't done classic event handling in more than a few years.
Sign In or Register to comment.