XForms: C++ && XForms

Christian Pomar (ipycp@arrakis.es)
Mon, 16 Mar 1998 20:06:18 +0100

# To subscribers of the xforms list from "Christian Pomar" <ipycp@arrakis.es> :

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;
assert(theObject);
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
class.

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
_________________________________________________
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/