Event Sequence in Visual FoxPro
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.
Visual FoxPro Event Sequence
Object |
Event that occurs |
---|---|
Data environment |
|
Form set |
|
Form |
|
Data environment cursor(s) |
|
Data environment |
|
Objects 1 |
|
Form |
|
Form set |
|
Form set |
|
Form |
|
Object1 2 |
|
Form |
|
Object1 |
|
Object1 |
|
Object1 |
Valid 3 |
Object1 |
|
Object2 3 |
|
Object2 |
|
Object2 |
|
Object2 |
Valid 4 |
Object2 |
|
Form |
|
Form |
|
Object 5 |
|
Form |
|
Form set |
|
Data environment |
|
Data environment |
|
Data environment cursor(s) |
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
Event Sequence Example
The following example uses a form to illustrate the order in which events occur in response to user interaction.
A sample form
In this example, the user performs the following actions:
Runs the form.
Types text in the Text1 text box.
Selects the text and copies it to the Clipboard.
Moves to the Text2 text box by pressing the TAB key.
Pastes the text into Text2.
Closes the form by clicking the Command2 command button.
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:
DO FORM form1 NAME frmObject
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 |
|
Form1 |
|
DataEnvironment |
|
Text1 |
|
Text2 |
|
Command1 |
|
Command2 |
|
Form1 |
|
Form1 |
|
Form1 |
|
Text1 |
|
Text1 |
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.
Object |
Event |
Parameters |
---|---|---|
Text1 |
(84 for "T", 1) |
|
Text1 |
|
|
Text1 |
(101 for "e", 0) |
|
Text1 |
|
|
Text1 |
(115 for "s", 0) |
|
Text1 |
|
|
Text1 |
(116 for "t",0) |
|
Text1 |
|
Action 3
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.
Object |
Event |
Parameters |
---|---|---|
Form1 |
(0, 0, 100, 35) |
|
Text1 |
(0, 0, 44, 22) |
|
Text1 |
(1, 0, 44, 22) |
|
Text1 |
(1, 0, 44, 22) |
|
Text1 |
|
|
Text1 |
(1, 0, 44, 22) |
|
Text1 |
(1, 0, 44, 22) |
|
Text1 |
|
Action 4
The user moves to the text box, Text2, by pressing the TAB key.
Object |
Event |
Parameters |
---|---|---|
Text1 |
(9, 0) |
|
Text1 |
|
|
Text1 |
|
|
Text2 |
|
|
Text2 |
|
Action 5
The user pastes the text into the text box, Text2, by pressing CTRL+V.
Object |
Event |
---|---|
Text2 |
Action 6
The user clicks the command button, Command2, to close the form.
Object |
Event |
|
---|---|---|
Form1 |
|
|
Command2 |
|
|
Text2 |
|
|
Command2 |
|
|
Text2 |
|
|
Command2 |
|
|
Command2 |
(1, 0, 143, 128) |
|
Command2 |
(1, 0, 143, 128) |
|
Command2 |
|
|
Command2 |
|
|
Command2 |
|
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 |
|
Command2 |
|
Command1 |
|
Text2 |
|
Text1 |
|
Form1 |
|
DataEnvironment |
|
DataEnvironment |