The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 3.0
SUMMARY
FoxPro version 2.x provided a TIMEOUT clause on the READ command. If no
user input activity occurred during the specified interval, the read
operation would stop. You can duplicate this functionality with a timer
control on a form in Visual FoxPro. The enhanced event model in Visual
FoxPro allows greater control over exactly which events cause a form to
time out. For example, you can cause the form to close if the mouse is
clicked even though no key was pressed. This article shows you how.
MORE INFORMATION
Step-by-Step Example
The following process sets two form level properties (dtKeyPress and
dtMouseMove) to store the time of the last keystroke or mouse movement. The
timer control verifies the elapsed time since the last occurrence of these
two events. If more than the specified interval has elapsed, the form is
released.
- Create a new form. Add the following properties to the form:
dtCurrTime
dtKeyPress
dtMousemove
- In the Init method of the form, add the following code:
ThisForm.DtKeyPress = DATETIME()
ThisForm.dtMouseMove = DATETIME()
- In the KeyPress method of the form, add the following code:
ThisForm.dtKeyPress = DATETIME()
- In the MouseMove method of the form, add the following code:
ThisForm.dtMouseMove = DATETIME()
- Add a timer control to the form. Set the Interval property of the timer
to the desired number of seconds * 1000. Add the following code to the
TimerEvent method of the timer:
lnIntervalInSeconds = This.Interval / 1000
ThisForm.dtCurrTime = DATETIME()
IF ThisForm.dtCurrTime - ThisForm.dtMousemove >= lnIntervalInSeconds ;
AND ;
ThisForm.dtCurrTime - ThisForm.dtKeypress > = lnIntervalInSeconds
ThisForm.Release
ENDIF
- Add a text box to the form for testing purposes. Save and run the form.
- The form should time out and release after the specified number of
milliseconds.
Incorporating a Timeout into a Formset
To adapt this example to close an entire formset, follow these steps:
- Create the three properties specified in step 1 of the example so that
they are created at the formset level.
- Place the Init code specified in step 2 in the Init method of the
formset. Change the reference of ThisForm to ThisFormSet.
- Create the timer control on each individual form in the formset. This is
required because the formset itself does not contain KeyPress and
MouseMove events. Each form in the formset must maintain its own
unique timer, but the formset itself must maintain the information as
to whether the user has interacted with any form within the formset.
Change all ThisForm references to ThisFormSet within this method.
- Change the reference of ThisForm in steps 3 and 4 of the example to
ThisFormSet.