Re: XForms: Demo dirlist, comes with distribution

Steve Lamont (spl@szechuan.ucsd.edu)
Sun, 1 Mar 98 21:52:17 PST

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

> fdui->fbform->fdui = fdui;
>
> What is the general idea of this line. This seems to me to be seting the
> forms fdui pointer to a pointer that is pointing to the form just defined.

Exactly.

The idea is that if you need to access the structure from a callback
you don't need a global variable. Global variables, according to some
theories of C programming, are Considered Harmful and to be avoided.

For instance, if the callback function `some_callback' which is called
to handle some action for an object in the form `whatever' needs to
access other members of the FD_whatever structure, you could code
something like

void some_callback( FD_OBJECT *ob, long data )

{

FD_whatever *whatever = ( FD_whatever *) ob->form->fdui;

[...]

Then you could manipulate any of the objects in that structure as you
desire.

As I said, this presupposes that the callback is invoked from an
object that is part of the FD_whatever structure. If if isn't then
you either need to resort to a global pointer or some other mechanism,
such as a pointer to structure attached to all FD_* structures which
provides a place to hang pointers to any other structures.

It can be a bit confusing at first but once you set these things up
the first couple of times it becomes pretty much second nature.

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://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/