Re: XForms: problem with fl_show_form

Steve Lamont (spl@szechuan.ucsd.edu)
Tue, 12 Aug 97 05:52:12 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> Here is a very simple program.
> When I run it and click on the button "print", no window pops up.
> I am missing something but I don't know what.
> [...]
> void PrintCB(FL_OBJECT *ob, long data)
> {
> FD_PrintForm *fd_PrintForm;
> fl_show_form(fd_PrintForm->PrintForm, FL_PLACE_MOUSE | FL_FREE_SIZE,
> FL_FULLBORDER, "Print");
> }
>
> int main(int argc, char *argv[])
> {
> FD_ButtonPrint *fd_ButtonPrint;
> FD_PrintForm *fd_PrintForm;
>
> fl_initialize(&argc, argv, 0, 0, 0);
> fd_ButtonPrint = create_form_ButtonPrint();
> fd_PrintForm = create_form_PrintForm();
> [...]

The variable fd_PrintForm in PrintCB() is a local variable. It is not
initialized or, rather, it is initialized -- with junk from the
stack. I'm surprised the code doesn't core dump.

What you probably want to do is:

void PrintCB(FL_OBJECT *ob, long data)
{
FD_PrintForm *fd_PrintForm;

fd_PrintForm = create_form_PrintForm();
fl_show_form(fd_PrintForm->PrintForm, FL_PLACE_MOUSE | FL_FREE_SIZE,
FL_FULLBORDER, "Print");
}

or make fd_PrintForm by

FD_ButtonPrint *fd_ButtonPrint;

void PrintCB(FL_OBJECT *ob, long data)
{
extern FD_PrintForm *fd_PrintForm;
fl_show_form(fd_PrintForm->PrintForm, FL_PLACE_MOUSE | FL_FREE_SIZE,
FL_FULLBORDER, "Print");
}

int main(int argc, char *argv[])
{
extern FD_ButtonPrint *fd_ButtonPrint;
FD_PrintForm *fd_PrintForm;

fl_initialize(&argc, argv, 0, 0, 0);
fd_ButtonPrint = create_form_ButtonPrint();
fd_PrintForm = create_form_PrintForm();
[...]

making fd_ButtonPrint into a global.

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