This is an old story:

I have a form that initiates a lengthy batch processing loop. The command
buttons on the form are unclickable while the loop is running so I set
escape on, test for inkey() and exit if the user presses escape.... This get
me back to my read events statement and the buttons become alive again. This
method is as old as the hills and somewhat inelegant.

Are there any other or newer suggestions?
-Lew

Re: Escape, read events & loops by Bernhard

Bernhard
Thu Jan 11 11:02:14 CST 2007

Hi Lew,

> I have a form that initiates a lengthy batch processing loop. The command
> buttons on the form are unclickable while the loop is running so I set
> escape on, test for inkey() and exit if the user presses escape.... This get
> me back to my read events statement and the buttons become alive again. This
> method is as old as the hills and somewhat inelegant.
I assume the batch is a pure foxpro processing, no external program.
Then the way to go would be:
put some DOEVENTS every now and then in your batch. This lets the command
buttons react on user events.
In the cmd.Click event(s) set some variable, maybe a form property or what ever
fits your needs.
In the batch, every now and then check this variable. If it is set accordingly,
then you should gracefully end the batch.
If some of the command buttons have cmd.Cancel set to .T., then it fires its
click event if the user presses ESC.

Regards
Bernhard Sander

Re: Escape, read events & loops by Olaf

Olaf
Fri Jan 12 01:58:45 CST 2007

>If some of the command buttons have cmd.Cancel set to .T., then it fires its
>click event if the user presses ESC.

Yes, so that's the main point, but this click()
won't run if there is no doevents in the batch
processing loop. Still better than inkey().

So roughly it's:

cmdStart.Click()
Thisform.lStopprocessing = .F.
Thisform.Batchprocess()

cmdCancel.Cancel=.T.
cmdCancel.Click()
Thisform.lStopprocessing = .T.

Batchprocess
do while NOT thisform.lStopprocessing
....
doevents
...
doevents
...
doevents force
enddo

ESC then can stop the process.

Bye, Olaf.

Re: Escape, read events & loops by Lew

Lew
Fri Jan 12 08:25:05 CST 2007

I thought that doevents only enabled interruption by desktop processes
outside my app. I'll check this out. Thanks.
-Lew
"Olaf Doschke" <b2xhZi5kb3NjaGtlQHNldG1pY3MuZGU.strconv.14@t-online.de>
wrote in message news:eo7f3j$vo$01$1@news.t-online.com...
> >If some of the command buttons have cmd.Cancel set to .T., then it fires
> >its click event if the user presses ESC.
>
> Yes, so that's the main point, but this click()
> won't run if there is no doevents in the batch
> processing loop. Still better than inkey().
>
> So roughly it's:
>
> cmdStart.Click()
> Thisform.lStopprocessing = .F.
> Thisform.Batchprocess()
>
> cmdCancel.Cancel=.T.
> cmdCancel.Click()
> Thisform.lStopprocessing = .T.
>
> Batchprocess
> do while NOT thisform.lStopprocessing
> ....
> doevents
> ...
> doevents
> ...
> doevents force
> enddo
>
> ESC then can stop the process.
>
> Bye, Olaf.



Re: Escape, read events & loops by Jack

Jack
Fri Jan 12 08:50:38 CST 2007

No, other processes always run no matter what you do in VFP.

DOEVENTS runs the VFP event loop, which causes mouse and keyboard
events in your VFP program to fire.

If you use DOEVENTS you have to be very careful to prevent any events
that would be incompatible with the batch process that is running
(like starting the same batch process up again, deleting or modifying
data that the batch process is using, etc.). Also, you can't call
DOEVENTS from code that runs because of another DOEVENTS command (e.g.
while one batch process is running that calls DOEVENTS you can't allow
another batch process to start and also call DOEVENTS).

On Fri, 12 Jan 2007 09:25:05 -0500, "Lew Schwartz"
<lschwartz@sionline.com> wrote:

>I thought that doevents only enabled interruption by desktop processes
>outside my app. I'll check this out. Thanks.
>-Lew
>"Olaf Doschke" <b2xhZi5kb3NjaGtlQHNldG1pY3MuZGU.strconv.14@t-online.de>
>wrote in message news:eo7f3j$vo$01$1@news.t-online.com...
>> >If some of the command buttons have cmd.Cancel set to .T., then it fires
>> >its click event if the user presses ESC.
>>
>> Yes, so that's the main point, but this click()
>> won't run if there is no doevents in the batch
>> processing loop. Still better than inkey().
>>
>> So roughly it's:
>>
>> cmdStart.Click()
>> Thisform.lStopprocessing = .F.
>> Thisform.Batchprocess()
>>
>> cmdCancel.Cancel=.T.
>> cmdCancel.Click()
>> Thisform.lStopprocessing = .T.
>>
>> Batchprocess
>> do while NOT thisform.lStopprocessing
>> ....
>> doevents
>> ...
>> doevents
>> ...
>> doevents force
>> enddo
>>
>> ESC then can stop the process.
>>
>> Bye, Olaf.
>