> here is a solution.
> 
> have your event handler in a seperate file, and declare the 
> variables globally as static.. no one outsite can reach
> them.. so they are based on 'file-scope'.. not 
> global. :))
> 
> if all your form routines are in that file.. they can access
> the variable:
> 
> ie:
> ---
>   mainFormEvent.c
> 
>   static Byte myByte;
> 
>   void processEvent(Event e) 
>   {
>     myByte = ...
>   }
> 
>   void otherFunction()
>   {
>     myByte = ...
>   }
> ---
> 
> az.
> --
> Aaron Ardiri 
> Lecturer                       http://www.hig.se/~ardiri/
> University-College i G�vle     mailto:[EMAIL PROTECTED]
> SE 801 76 G�vle SWEDEN       
> Tel: +46 26 64 87 38           Fax: +46 26 64 87 88
> Mob: +46 70 352 8192           A/H: +46 26 10 16 11

A somewhat different approach, but one that more closely emulates the 
userdata feature of Windoze programming:

Boolean MyFormHandleEvent(EventPtr event)
{
    Boolean             handled;
    // other local automatic variables
    static struct
    {   int     onething;
        SWord   anotherthing;
        Boolean whatever;
    } *userdata;    // persistent data private to this form handler

    switch (event->eType)
    {
        case frmOpenEvent:
            userdata = MemPtrNew(sizeof(*userdata));
            // appropriate initialization of the *userdata
            // initialize and draw the form
            break;

        case ctlSelectEvent:
            // probably uses userdata->onething, etc.
            break;

        case frmCloseEvent;
            // whatever cleanup is necessary
            MemPtrFree(userdata);
            userdata = 0;
            break;
    }
    return handled;
}

If you are using a C compiler that is ANSI-compliant, userdata will be 
initialized to NULL when your app launches. And of course, you can 
figure out your own variations on this; maybe you want userdata to 
persist when the form closes, and be able to just use it next time the 
form opens.

--
Roger Chaplin
<[EMAIL PROTECTED]>

Reply via email to