Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Event processing
Message
 
To
29/04/2002 00:22:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00638933
Message ID:
00650325
Views:
19
Dennis,

DoEvents tells Fox to stop whatever it is doing and process the windows events that are pending. Under normal conditions Fox will not process mouse clicks and other windows events while it is running code.

One use of DoEvents is:

You have a form and there is a button that will run code that is in a loop. You want to privide a Cancel button that will stop this loop. The problem is that Fox will not process any mouse clicks until the loop is done. So your solution is to use the DoEvents command inside the loop to periodically process the windows events (including any mouse clicks).

The downside of DoEvents is that it slows code down so it is usually advisable to only DoEvents occasionally.
* Loop code checking for the cancel button
lnCnt = 1
SCAN
   blah
   blah
   IF MOD(lnCnt,100) = 0
      DOEVENTS
   ENDIF
   lnCnt = lnCnt + 1
ENDSCAN
Now you would need to do something in the Cancel button that the code above could sense. I usually set the Cancel property of the button to .T. and add code like this.
* Loop code checking for the cancel button
lnCnt = 1
llAbort = .F.
SCAN
   blah
   blah
   IF MOD(lnCnt,100) = 0
      DOEVENTS
      IF LastKey() = 27  && Escape
         llAbort = .T.
         EXIT
      ENDIF
   ENDIF
   lnCnt = lnCnt + 1
ENDSCAN
IF llAbort
   * Do what is needed to abort the process gracefully
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform