Re: XForms: problem with fl_get_input solved :)

Steve Lamont (spl@szechuan.ucsd.edu)
Sun, 12 Oct 97 22:38:25 PDT

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

> ... One other question I have regards program
> structure. I have about 10 different input fields in my
> application. I presently also have a call back for each one of
> them. This, to me, seems a bit excessive to have 10 callbacks being
> a few lines of code each. Is there a more efficient way of doing
> this? Is it possible to use the same call back for the different
> fields that pass data to the same structure? ...

It's possible but it may not be worth the effort.

You need to somehow differentiate the object for which the callback is
being called. You can do this by using the long data value passed in
the callback arguments. Define some set of constants which identify
the fields, set them in the `Argument' field of the fdesign Attribs
window, and then use a switch statement to choose between them at run
time:

void my_callback( FL_OBJECT *obj, long data )

{

char *string = strdup( ( char *) fl_get_input( obj ) );

switch ( data ) {

case 1: {

if ( my_struct.param_1 )
free( my_struct.param_1 );
my_struct.param_1 = string;
break;

}
case 2: {

if ( my_struct.param_2 )
free( my_struct.param_2 );
my_struct.param_2 = string;
break;

}
...

}

}

I'm not sure that this is any better than separate functions for each
object. It may be slightly messier to maintain if/when you add new
input fields to your structure and database.

I personally would stick with the individual callbacks.

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/