Re: XForms: u_?data in object struct - initialized?

Christopher Sean Hilton (chris@vindaloo.com)
Tue, 17 Mar 1998 21:57:56 -0500 (EST)

# To subscribers of the xforms list from Christopher Sean Hilton <chris@vindaloo.com> :

On Tue, 17 Mar 1998, Michal Szymanski wrote:

: # To subscribers of the xforms list from msz@bulge.astrouw.edu.pl (Michal Szymanski) :
:
: What do you mean by "fdesign generated routine"? A routine generating
: the object or routine initializing it?
: BTW, the simplest way I can imagine to do it is something like:
:
: FL_OBJECT *ob;
: ob = myform->first;
: while ( ob ) {
: ob->u_ldata = 0;
: ob = ob->next;
: }
:
: Is there a better way?
:

Mea Culpa here from me. I assumed that you were using fdesign which
gives you a comment that tells you right where you need to initialize
the variables in your form.

Having said that that's pretty much what I would do. Here's where I
would do it. I use fdesign which generates a structure with the name:
FD_<your form name>, a function which creates your form:
create_form_<your form name>, and optionally a function main which
calls the create function, and then uses fl_show_form() and
fl_do_forms(). To display and run the form. An excerpt of that main
function as I use it is shown here:

...
FD_main * fd_main;
FL_FORM * form;
FL_OBJECT * object;

/* fl_initialize(argc, &argv, 0, 0, 0); */

if ((fd_main = create_form_main()) != NULL) {

/* fill-in form initialization code */

form = fd_main->main;
form->u_vdata = form->u_cdata = NULL;
form->u_ldata = 0;

for (object = form->first; object != NULL; object = object->next) {
object->u_vdata = object->u_cdata = NULL;
object->u_ldata = 0;
}

/* show the first form */
fl_show_form(fd_main->main,FL_PLACE_CENTERFREE,FL_FULLBORDER,"main");
}

/* fl_do_forms(); */
....

I usually don't use the user data fields in individual objects so I
don't bother to initialize them. Fdesign gives you the option of having
a pointer to individual objects on the form so if I did use the user data
field on objects I would use the pointer from fdesign to initialize it.

: Well, I agree that to be 111% sure, one should initialize it himself.
: Still, it would be nice if the library would do it for the user
: *officially* (i.e. with appropriate statement in the manual). After all,
: you do not activate all your form's buttons by hand, do you? You
: probably presume that they are active by default.
:

Yes I do but I see this as a matter of scale. I would usually only use the
form's user data so my initialization is easy and concise and I would do
it even if the manual explicitly stated that the forms library had done it
already. If you are actually using all the user data pointers on all the
objects then you're right to assume some sort of initialization but I
still initialize them as a matter of style. That way when someone else
looks at your code they don't need to know the intimate details of the
forms library to debug a problem.

Chris

--
      __o          "All I was trying to do was get home from work."
    _`\<,_           -Rosa Parks
___(*)/_(*)____.___o____..___..o...________ooO..._____________________
Christopher Sean Hilton                    [chris/at/vindaloo/dot/com]

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