Re: XForms: Global data

Trent Piepho (xyzzy@u.washington.edu)
Thu, 12 Mar 1998 17:32:10 -0800 (PST)

# To subscribers of the xforms list from Trent Piepho <xyzzy@u.washington.edu> :

On Thu, 12 Mar 1998, Kevin Smith wrote:
> Chris wrote:
> > I'm new at programming in X, and XForms is the first library I've really
> > looked at in detail. I'm curious if there's a way to avoid using global
> > data for a program using XForms? I can't see how passing variables
> > (declared structures, etc) which haven't been declared globally, as
> > parameters to callback functions which are called by xforms, is possible.
> > If this issue has been brought up before, or if it's just general X
> > programming, or if I'm not making any sense, could somebody point me in
> > the right direction? My structures professor would kick my ass if I
> > handed in a project with global data.

You can use the data argument of the callback function to pass in any data you
want, say a pointer to something. There are also the u_[vcl]data fields of an
object where you can store stuff instead of making it global. It's generally
a pain to avoid global variables when you use callback type programming. You
can always use static globals and stick the callbacks in their own source file
to encapsulate your data more.

Lots of my callbacks need to access other objects in my forms, and I found
trying to avoid global data for this was too much of a pain. I would have one
button that was supposed to turn another off when clicked on. So I stick a
pointer to that button in u_vdata. Then later I need to get the value of some
counter or something, but u_vdata is already used. I guess I could make a
structure with members for every object the callback needs at access, but this
is just a nightmare. The best thing to do is take the fdui structure that
fdesign makes for you and make it global. This is only one global variable
per form, so it's not that bad. This way you can access any object you assign
a name to from anywhere you want.

|Gazing up to the breeze of the heavens \ on a quest, meaning, reason |
|came to be, how it begun \ all alone in the family of the sun |
|curiosity teasing everyone \ on our home, third stone from the sun. |
|Trent Piepho (xyzzy@u.washington.edu) -- Metallica |

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