Luc Le Blanc wrote:
> Does PrgUserCancel work when tapping the Cancel button in Progress
> dialogs? I wonder because I sprinkled the code of a lengthy computation
> process (60s on a IIIxe) with calls to this macro, but I never get a
> true when I tap or hold the stylus on the Cancel button of the Progress
> dialog. I then converted all these calls into calls to a UserAbort
> function:
>
> Boolean UserAbort( ProgressPtr progress )
> {
> if ( PrgUserCancel( progress ) )
> return true;
> else
> return false;
> }
>
> to conveniently put a breakpoint on the "return true" line, which I
> never hit. But if I put a breakpoint on the test, I keep stopping, which
> proves I do call this function often.
I've never used the built-in progress stuff, but I'm guessing you need
to call PrgHandleEvent() and you're not.
Here's an interesting article about using the built-in progress stuff:
http://www.developer.com/lang/other/article.php/615961
One thing I don't understand about the example code in that article
is it does this inside its loop:
EvtGetEvent(&event, 0);
if (!PrgHandleEvent(prg, &event))
if (PrgUserCancel(prg))
break;
Seems like that should be a loop instead of an if statement, since
by the very nature of it, using a progress bar indicates you're
probably doing something slow which is divided into chunks which
individually might be also slow. Which means by the time you've
finished a whole chunk, you might have multiple events queued up.
Without a loop, you only process a single event per chunk of your
operation.
So, I wonder, wouldn't it be better to do something like this?
Boolean canceled;
canceled = false;
while (true)
{
EvtGetEvent (&event, 0);
if (event.eType == nilEvent)
break;
if (! PrgHandleEvent (prg, &event))
{
if (PrgUserCancel (prg))
{
canceled = true;
break;
}
}
}
That way, when they do hit cancel, or whatever, all the events in
the queue will get handled right away instead of one per chunk.
- Logan
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/