Re: XForms: C++ && XForms

Ian Leonard (
Thu, 16 Apr 1998 17:22:43 +0100 (BST)

# To subscribers of the xforms list from (Ian Leonard) :

>From the keyboard of Christian Pomar comes:-
># To subscribers of the xforms list from "Christian Pomar" <> :
>Hi All,
>Just one note about using C++ and XForms via de u_vdata pointer.
>If you use callbacks for all the controls in a form, fl_do_forms will
>never come back so the method you may be running (for example,
>theObject.Run()) will never end so the object will never be destroyed.
>If you have some controls without callbacks (for example the "OK" and
>"Cancel" buttons in most of the forms) and fl_do_forms returns with the
>pointer to one of them you can end the form (and the object) in a normal
>way (reaching the object destructor if necessary). The problem can arise
>again if you use fl_set_form_atclose and a static member of the class.
>Again, your loop will never end and the object will not be destructed in
>a normal way.
>I am thinking in using pointers to objects to avoid all these problems.
>ObjectClass *theObject;
>theObject=new ObjectClass;
>theObject->SetUp(); // Set everything up
>theObject->Run(); // It will never come back because fl_do_forms
>never comes // back.
> // Or it finishes with the AtClose routine.
>Somewhere, in the exit callback (warning: a static method):
>void ObjectClass::_TheLastStaticCallback(FL_OBJECT *ob,long in)
> ObjectClass *pointer2Object=(ObjectClass*)ob->form->u_vdata;
> pointer2Object->TheLastCallback(); // The last Callback
>should kill the form
> // When the method ends, we kill the object
> delete pointer2Object; // This
>really frees the object
> ...
>Another way to do this is not even using pointers. Just delete the object
>even if it hasn't been created with new but as a normal instance of a
>Well, this seems to work. Does anybody think of any problem with this
>solution? I have tried it and it works.
>Best Regards,
>Christian Pomar


How about this:

#include <setjmp.h>
static jmp_buf jmp;
static int jmp_flag = 0;

BASECLASS::end ( int val)
if ( jmp_flag)
longjmp ( jmp, val);
fprintf ( stderr, "Warning! run () has not been called\n");

int n;

// Should only be called by a main clas

jmp_flag = 1;
if ( n = setjmp ( jmp)) {
printf ( "JMP BACK\n");
fl_finish ();
return ( n);


while (1);

A->start ();

// End of Xforms stuff

Any button that wants to end it all should call A->end ( acode)


Ian Leonard eMail: Phone Fax: +44 (0)1865 434757 Fax: +44 (0)1865 434758 19 Stapleton Road Headington, Oxford, OX3 7LX, UK

Please ignore spelling and punctuation - I did.

_________________________________________________ To unsubscribe, send the message "unsubscribe" to or see XForms Home Page: List Archive: