Re: XForms: Accessing objects in a form

Frank Stefani (EAD-Frank.Stefani@t-online.de)
Fri, 20 Jun 1997 08:58:32 +0200

To subscribers of the xforms list from EAD-Frank.Stefani@t-online.de (Frank Stefani) :

Steve Lamont wrote:
>
> To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
>
> > I suggest you should declare "theFduiPtr" as a global variable
> > in your source file which has "main()" in it:
> >
> > FD_whatever *theFduiPtr;
> >
> > Just this short declaration, NOT
> > "FD_whatever *theFduiPtr = (FD_whatever *)ob->form->fdui ;".
>
> Why?
>
> Although I suppose this is a matter of programming style whether you
> rely upon global variables or not, the fdui field in the FL_FORM data
> structure was designed to do precisely what it does, which is to
> provide a link back to the fdesign generated user interface structure.
>
> I know this since it was more or less at my instigation, as far as I'm
> aware, that this mechanism was implemented.
>
> BTW, the construction I actually use is to declare the following in a
> header file included in all sources which have the need of
> manipulating the FD structures:
>
> typedef struct {
> FL_FORM *form;
> void *vdata;
> long ldata;
> } FD_generic;
>
> #define GENERIC(obj) ( ( FD_generic *)obj->form->fdui )
> #define DUI(cast,obj) ( ( cast *) GENERIC( obj ) )
>
> This can then be used as
>
> void some_callback( FL_OBJECT *obj, long data )
>
> {
>
> FD_whatever *whatver = DUI( FD_whatever, obj );
>
> [...]
>
> }
>
> Obvious extensions are
>
> #define DUI_VDATA( obj ) ( GENERIC( obj )->vdata )
> #define DUI_LDATA( obj ) ( GENERIC( obj )->ldata )
>
> Bear in mind that if you have multiple instantiations of the
> FD_whatever form, you'd have to keep multiple global FD_whatever
> pointers and keep track of which one is which in some manner.
>
> Of course, again, this is largely a matter of style and can be
> something of a religious issue. I tend to avoid global variables
> almost at all costs and find the mechanisms described above helpful in
> managing data and context in complicated XForms applications where I
> have multiple instantiations of forms.

Thanks for your brief and interesting explanation, Steve. I usually
avoid global variables, too. When I started with XForms, I found some
things to be complicated to do. Object access in multiple forms is
such a thing and as we know from reading the mails this point comes
up again and again. So perhaps the documentation could explain this
point more clearly.

Since my start with XForms, I never again really thought about my
way with globals, simply because it works. But you are right: the
better way is described in your code pieces :-)

Have a nice weekend, you deserve it,
Frank.

-- 
---------------------------------------------------------------
     _/_/_/_/     _/_/     _/_/_/    EAD-Systeme GmbH
    _/          _/  _/    _/    _/   Nachfeldstr. 4
   _/_/_/     _/    _/   _/     _/   D-82490 Farchant, Germany
  _/        _/_/_/_/_/  _/     _/    Phone: +49 8821 9623-0
 _/_/_/_/ _/        _/ _/_/_/_/      Fax: +49 8821 9623-20
---------------------------------------------------------------
Email: EAD-Frank.Stefani@t-online.de
---------------------------------------------------------------

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