Re: XForms: Xforms and Prolog...

Steve Lamont (spl@szechuan.ucsd.edu)
Mon, 20 Jul 98 10:17:01 PDT

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

> can anybody tell me how to pass a file selected by the user (by file
> selector) to a callback function (as argument) ?

By file, I presume you either mean a file pointer (of type FILE) or a
file name (a pointer to string).

You can't, directly (or at least you don't want to).

The easiest way to pass information between callbacks is to use the
void or char pointers attached to each object's data structure (or use
the similar pointers in the form or fdui data structures, if you
wish).

So, for example, say you have a form with has two objects, foo and
bar, and you want to pass a filename between them. You'd code
something like

void foo_cb( FL_OBJECT *obj, long data )

{

FD_whatever *whatever = ( FD_whatever *) obj->form->fdui;
const char *filename = fl_show_fselector( ... );

whatever->bar->u_cdata = ( char *) filename;

...

}

void bar_cb( FL_OBJECT *obj, long data )

{

if ( obj->u_cdata ) {

FILE *f = fopen( obj->u_cdata, ... );

...

}

}

The temptation exists to use the `data' parameter of the callback for
passing this information. However, try to resist -- this is bad
programming practice. Different architectures implement longs and
pointers with different word lengths. While it is probably unusual
that a pointer and a long have differing lengths, I don't believe they
are guaranteed to be the same. I'd have to check my handy K&R to be
sure and it's not here at the moment.

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/