Discussion:
Command Button Click Event Question
(too old to reply)
MikeA
2010-06-03 03:57:32 UTC
Permalink
Here's an interesting question:

I've seen some programs where there's a button you can click on to "PAUSE"
execution or even QUIT. I'm trying to figure out the best way to do this
when program code is executing. I know the click event MIGHT respond once
current code is done executing. I know I could use MouseMove and let the
user just keep the cursor over a button until the current code is done and
then it mousemove code will execute but I think that is rather sloppy and a
click event is a better way to go.

I put two buttons on a form. The first button's click event has this:

lnSec = int(seconds())

do while lnSec + 15 > seconds()
enddo
acti screen
? "DONE"

This causes VFP to use a lot of CPU cycles. Now, the question is how can I
throw a second button on the form so that if they click it the caption will
immediately change to something like OK or Please Wait or Resume...etc. In
addition, I could set a property so that the current code executing or a
timer could take action from there.

I notice that in the tight loop if they click a second button where I have
something like MessageBox("CLICKED") that the click event never even fires
at all (if it is clicked early on in the above tight loop.

Any ideas before this forum comes to a close?

Thanks,
Mike
MikeA
2010-06-03 04:10:15 UTC
Permalink
It looks like my friend DOEVENTS will help me but if any of you have
anything to add that will be great.

The only problem I can see now is that sometimes when VFP is in a really
tight loop or doing something that requires a lot of CPU cycles then the
mouse cursor disappears. If there is no mouse cursor then they can't click
the button. The only other problem I can see is that DOEVENTS can slow down
the program but I'm not sure how much if I don't call it to often.

Mike
Post by MikeA
I've seen some programs where there's a button you can click on to "PAUSE"
execution or even QUIT. I'm trying to figure out the best way to do this
when program code is executing. I know the click event MIGHT respond once
current code is done executing. I know I could use MouseMove and let the
user just keep the cursor over a button until the current code is done and
then it mousemove code will execute but I think that is rather sloppy and
a click event is a better way to go.
lnSec = int(seconds())
do while lnSec + 15 > seconds()
enddo
acti screen
? "DONE"
This causes VFP to use a lot of CPU cycles. Now, the question is how can
I throw a second button on the form so that if they click it the caption
will immediately change to something like OK or Please Wait or
Resume...etc. In addition, I could set a property so that the current
code executing or a timer could take action from there.
I notice that in the tight loop if they click a second button where I have
something like MessageBox("CLICKED") that the click event never even fires
at all (if it is clicked early on in the above tight loop.
Any ideas before this forum comes to a close?
Thanks,
Mike
MikeA
2010-06-03 05:03:17 UTC
Permalink
In my testing it looks like trying to issue a DOEVENTS every couple seconds
really slow things down.

It seems like it's not easy to set up a button to pause or stop program
execution. I think the Escape key will probably work with ON ESCAPE. But,
I'm not sure how to manage this with a button.

Any ideas?
Post by MikeA
It looks like my friend DOEVENTS will help me but if any of you have
anything to add that will be great.
The only problem I can see now is that sometimes when VFP is in a really
tight loop or doing something that requires a lot of CPU cycles then the
mouse cursor disappears. If there is no mouse cursor then they can't
click the button. The only other problem I can see is that DOEVENTS can
slow down the program but I'm not sure how much if I don't call it to
often.
Mike
Post by MikeA
I've seen some programs where there's a button you can click on to
"PAUSE" execution or even QUIT. I'm trying to figure out the best way to
do this when program code is executing. I know the click event MIGHT
respond once current code is done executing. I know I could use
MouseMove and let the user just keep the cursor over a button until the
current code is done and then it mousemove code will execute but I think
that is rather sloppy and a click event is a better way to go.
lnSec = int(seconds())
do while lnSec + 15 > seconds()
enddo
acti screen
? "DONE"
This causes VFP to use a lot of CPU cycles. Now, the question is how can
I throw a second button on the form so that if they click it the caption
will immediately change to something like OK or Please Wait or
Resume...etc. In addition, I could set a property so that the current
code executing or a timer could take action from there.
I notice that in the tight loop if they click a second button where I
have something like MessageBox("CLICKED") that the click event never even
fires at all (if it is clicked early on in the above tight loop.
Any ideas before this forum comes to a close?
Thanks,
Mike
Gene Wirchenko
2010-06-03 17:53:28 UTC
Permalink
On Wed, 2 Jun 2010 20:57:32 -0700, "MikeA" <***@appellsoftware.com>
wrote:

[snip]
Post by MikeA
This causes VFP to use a lot of CPU cycles. Now, the question is how can I
throw a second button on the form so that if they click it the caption will
immediately change to something like OK or Please Wait or Resume...etc. In
addition, I could set a property so that the current code executing or a
timer could take action from there.
How? Cheat.

I have not tested the following, but I have done something
similar. I used sys(1270), but this looks to be shorter.

In the code that should be interruptible, put occasional calls to
a method that checks for clicking on a quit button:

if this.interrupt()
* Do abort stuff here.

The method would be something like:

procedure interrupt

* Mouse click?
if inkey("m")#151 && No.
return .f.
endif

* Get mouse data.
local mousedata(1)
=amouseobj(mousedata)
return mousedata(1)=objquitbutton

endproc

with objquitbutton being an object reference to the quit button.
Post by MikeA
I notice that in the tight loop if they click a second button where I have
something like MessageBox("CLICKED") that the click event never even fires
at all (if it is clicked early on in the above tight loop.
messagebox() is modal.
Post by MikeA
Any ideas before this forum comes to a close?
I have plenty of time then.

Sincerely,

Gene Wirchenko

Continue reading on narkive:
Loading...