Event Sequence in Visual FoxPro
Event Sequence in Visual FoxPro
yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm
Though some events occur as single events, a user action often triggers multiple events. Some of
these events occur independently; however, some event sequences are fixed, for example, the event
sequence that occurs when a form is created or destroyed.
When a sequence of events is triggered for a control, the entire sequence of events is associated
with the control. For example, suppose you click the left mouse button on a command button and
the drag the mouse pointer away from the command button. The command button's MouseMove
event continues to occur even though the mouse pointer moves over the form. If you release the
left mouse button over the form instead of over the command button, the MouseUp event that
occurs is associated with the command button instead of the form.
The following table shows the general sequence of Visual FoxPro events, assuming that the data
environment's AutoOpenTables property is set to True (.T.). Other events can occur based on user
interaction and system response.
Form Load
Objects 1 Init
Form Init
Form Activate
Object1 2 When
Form GotFocus
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 1/7
31/12/2018 Event Sequence in Visual FoxPro
Object1 GotFocus
Object1 Message
Object1 ValidВ 3
Object1 LostFocus
Object2 3 When
Object2 GotFocus
Object2 Message
Object2 ValidВ 4
Object2 LostFocus
Form QueryUnload
Form Destroy
Object 5 Destroy
Form Unload
1. For each object, from innermost object to outermost container 2. First object in the tab order 3.
Next object to get focus 4. As the object loses focus 5.For each object, from outermost container to
innermost object
The following example uses a form to illustrate the order in which events occur in response to user
interaction.
These actions trigger system events for each object. The following tables list the events that occur in
response to each user action.
Note:
In this example, the Paint event has been removed from the tables because this event occurs frequently and
makes it difficult to see the sequences of the other events.
Action 1
The user runs the form by typing the following command in the Command window:
В Copy Code
Visual FoxPro loads the form, initializes each object, and then initializes the form. The form is
activated and the first text box receives input focus.
Object Event
DataEnvironment BeforeOpenTables
Form1 Load
DataEnvironment Init
Text1 Init
Text2 Init
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 3/7
31/12/2018 Event Sequence in Visual FoxPro
Command1 Init
Command2 Init
Form1 Init
Form1 Activate
Form1 GotFocus
Text1 When
Text1 GotFocus
Action 2
The user types the text "Test" in the text box, Text1. Each keystroke generates two events.
Note:
The KeyPress event receives two parameters: a number representing the pressed key and the state of the
SHIFT, ALT, and CTRL keys.
Text1 InteractiveChange В
Text1 InteractiveChange В
Text1 InteractiveChange В
Text1 InteractiveChange В
Action 3
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 4/7
31/12/2018 Event Sequence in Visual FoxPro
The user selects the text in the text box, Text1, by double-clicking the text and copies the text to the
Clipboard by pressing CTRL+C. Mouse events and a Click event accompany the DblClick event.
Note:
The MouseMove, MouseDown, and MouseUp events receive four parameters: a number indicating the
pressed button, the state of the SHIFT key, and (X, Y) coordinates. The X and Y coordinates are relative to the
form and reflect the form's scale mode, for example, pixels. Though only one MouseMove event is listed for
each control, in actuality, this event can occur half a dozen times or more.
Text1 Click В
Text1 DblClick В
Action 4
The user moves to the text box, Text2, by pressing the TAB key.
Text1 Valid В
Text1 LostFocus В
Text2 When В
Text2 GotFocus В
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 5/7
31/12/2018 Event Sequence in Visual FoxPro
Action 5
The user pastes the text into the text box, Text2, by pressing CTRL+V.
Object Event
Text2 InteractiveChange
Action 6
The user clicks the command button, Command2, to close the form.
Object Event В
Form1 MouseMove В
Command2 MouseMove В
Text2 Valid В
Command2 When В
Text2 LostFocus В
Command2 GotFocus В
Command2 Click В
Command2 Valid В
Command2 When В
When the form closes and objects are released, additional events take place in the opposite order
of the events listed for Action 1.
Object Event
Form1 Destroy
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 6/7
31/12/2018 Event Sequence in Visual FoxPro
Command2 Destroy
Command1 Destroy
Text2 Destroy
Text1 Destroy
Form1 Unload
DataEnvironment AfterCloseTables
DataEnvironment Destroy
See Also
Send comments about this topic to Microsoft. В© Microsoft Corporation. All rights reserved.
http://www.yaldex.com/fox_pro_tutorial/html/14fedca4-268d-4abb-af1f-091f5f5240c5.htm 7/7