> You should do basically what you're doing (calling EvtSysEventAvail).  A
> good example of this are the Palm PIM apps in their search routine.  If you
> look there I bet you notice one thing different from your code. :)
> 
> 
> >The problem is that EvtEventAvail() never returns false, even though
> >the only event on the queue is the custom event I'm currently
> >processing.  I'm guessing that an event isn't removed from the queue
> >until the handler returns true
> 
> Yes.  Often if your code is activated by the user tapping a button, then a
> penUpEvent is still on the queue.

I'd already tried EvtSysEventAvail.  It's working as advertised, as far
as I can tell.  But my "midterm-abort" algorithm still isn't aborting.

The problem as far as I can tell is that I'm never getting the event
that caused EvtSysEventAvail to return true.  Is it possible that
that's because the custom "resume" event I post after checking
EvtSysEventAvail gets put ahead of the existing event on the queue?
That would explain why when I bubble back up to the main event loop
and call EvtGetNextEvent (or whatever it's called :-) what I get back
is the custom event I just posted.  What I *want* is to get that event
only after I've processed the event that was on the queue before.

Here's an outline of the code (from memory; I'm at work and my PalmOS
projects live at home).  The result is an infinite loop 

void MainEventLoop() {
        for ( ; ; ) {
                if ( EvtGetNextEvent( &evt ) {
                        switch ( evt.eType ) {
                                case myCustomEvent:
                                        resumeCalculation( &evt );
                                        result = true;
                                        break;
                        ...
                }
        }
}

void resumeCalculation( EventPtr e ) {
        while ( doSomeWork(e) ) {
                if ( EvtSysEventAvail( true ) ) {
                        EventType customEvt;
                        customEvt.eType = myCustomEvent;
                        EvtAddEventToQueue( &myCustomEvent );
                        break;
                }
        }
}

So once there's *some* event on the queue I post a custom event, but I
get that event right back as soon as I call GetNextEvent().  And since
the original (System) event's *still* on the queue EvtSysEventAvail will
return true next time I call it and I'll post my event and...and...
I get an infinite loop and never do handle what the user wants done.

I suppose I could do this with global variables, but that smells wrong.

Thanks!

--Eric House

******************************************************************************
* From the desktop of: Eric House, [EMAIL PROTECTED]                            *
*     Check out Crosswords for PalmOS: <http://www.peak.org/~fixin/xwords>   *
*          "The instructions said 'Win98 or better' -- so I installed Linux" *
******************************************************************************

Reply via email to