Freigeben über


Controlling the Event Loop

Once the environment is set up and you've displayed the initial user interface, you're ready to establish an event loop to wait for user interaction.

To control the event loop

  • Issue the READ EVENTS command, which causes Visual FoxPro to begin processing user events such as mouse clicks and keystrokes.

It is important to place the READ EVENTS command correctly in your main file, because all processing in the main file is suspended from the time the READ EVENTS command is executed until a subsequent CLEAR EVENTS command is issued. For example, you might issue a READ EVENTS command as the last command in an initialization procedure, executed after the environment has been initialized and the user interface displayed. If you don't include the READ EVENTS command, your application will return to the operating system after running.

After the event loop has been started, the application is under the control of the user interface element that was last displayed. For example, if the following two commands are issued in the main file, the application displays the form Startup.scx:

DO FORM STARTUP.SCX
READ EVENTS

If you don't include a READ EVENTS command or its equivalent in your main file, your application will run properly from the Command window within the development environment. However, when you run it from your menu or main screen, the application will appear briefly, then quit.

Your application must also provide a way to end the event loop.

To terminate the event loop

  • Issue the CLEAR EVENTS command.

Typically, you issue the CLEAR EVENTS command from a menu or a button in a form. The CLEAR EVENTS command suspends the event processing for Visual FoxPro and returns control to the program that issued the READ EVENTS command that started the event loop.

For a simple program example, see Structuring a Program as a Main File.

Caution   You need to establish a way to exit the event loop before you start it. Make sure your interface has a mechanism (such as an Exit button or menu command) to issue the CLEAR EVENTS command.

See Also

Initializing the Environment | Structuring a Program as a Main File | Compiling an Application | READ EVENTS COMMAND | Adding Files to a Project