Re: XForms: Problems with parameter passing within callbacks...

T.C. Zhao (tc_zhao@yahoo.com)
Thu, 3 Sep 1998 14:08:34 -0700 (PDT)

# To subscribers of the xforms list from "T.C. Zhao" <tc_zhao@yahoo.com> :

You can not use a memember function of a C++ class as a
callback as the function does not compatible with
any other functions, certainly not compatible with
all C functions (due to the magic this pointer).
What you can do is pass the *class* pointer to the callback
function, and call the memember function from within the callback.
Another choice is just make the member function static.

Also, never use cast to prevent compiler from complaining
unless you absolutely sure you understand why it's complaining.
Time spent in understanding the error messages probably
wounds up less than the time taken wondering why the program does
not work right..

---Humberto Cervantes Cuevas <hcc@hp9000a1.uam.mx> wrote:
>
> # To subscribers of the xforms list from Humberto Cervantes Cuevas
<hcc@hp9000a1.uam.mx> :
>
> Hello! I am quite new to this mailing list and maybe this problem
has been
> discussed before, but i would appreciate very much any solution...
>
> I am programming in C++ and i have tried to encapsulate a form
within a
> class. Inside the declaration of the class, i have put the following
> members (this is a simplified version):
>
> class MyWindow
> {
> protected:
> int winID;
> FD_mywindow *mywin;
> void CanvasHandler();
>
>
> public:
>
> bool OpenWindow();
> bool ActivateWindow();
> bool CloseWindow();
>
> FD_mywindow *create_form_mywindow(void);
>
> // Callbacks
>
> void On_FILE_MENU(FL_OBJECT *ob,long data);
>
> };
>
> The form consists of a simple file menu.
>
> The problem i have appears when assigning the callbacks.
>
> Inside the member create_form_mywindow(void) i have the following
lines:
>
> FD_mywindow *create_form_mywindow(void)
> {
> .
> .
> .
> fdui->FILE_MENU = obj = fl_add_menu(...);
> fl_set_object_boxtype(obj,FL_FRAME_BOX);
>
> fl_set_object_callback(obj,(FL_CALLBACKPTR)On_FILE_MENU,1);
>
> .
> .
> .
> }
>
> As you can see i assign the pointer to the member function
On_FILE_MENU to
> the callback, the cast to FL_CALLBACKPTR is necessary otherwhise i
get the
> following error:
>
> "a pointer to a bound function may only be used to call the function"
>
> after compilation everything seems fine... I can press on the Menu
item
> and the function assigned to the callback is executed, BUT there is a
> problem, when i want to read the argument i don't get the value i
sent...
>
> WHY ???
>
> I noticed also that any of the attributes or variables of the class,
like
> winID in my example can't be read correctly inside any of the callback
> functions but can be read correctly in any other of the functions
before
> and after the callback is executed.
>
> I will appreciate very much any ideas on the solution to this problem.
>
> Thank you very much.
>
> Humberto Cervantes
> hcc@hp9000a1.uam.mx
>
> _________________________________________________
> To unsubscribe, send the message "unsubscribe" to
> xforms-request@bob.usuf2.usuhs.mil or see
> http://bob.usuf2.usuhs.mil/mailserv/xforms.html
> XForms Home Page: http://bragg.phys.uwm.edu/xforms
> List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/
>
>

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at /cgi-bin/exit-to?http://mail.yahoo.com

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/