FoxPro form flashes on the screen and vanishes

Everybody meets this problem with their first executable; the program runs well in the development environment but fails when run from Windows. The FoxPro window just flashes on the screen and then vanishes. You can search VFP Help for terms like "flash", "vanish" and "disappear" but you will find nothing. The information is hidden away under "How to: Control the Event Loop" and you won't be able to ship your exe until you find it.

This problem crops up because Visual FoxPro is now an event-driven language. It runs through the code for your form, reaches the end, and the program terminates when there is nothing more to do. Everything vanishes from the screen. The same thing will happen if your application is based on a main menu; FoxPro will run through the code to create the menu, the menu will flash on the screen but then the program terminates and the menu vanishes.

The solution is a simple one once you realise what FoxPro is doing. You have to tell FoxPro to start its event-processing loops. The command that does this is:

Read Events

You'll need to add this code in different places depending on whether you are using a form, a menu or a program as the main element of your application.

If you are using a form then add this as the last line in the Activate event. This will allow the form to load and initialise itself before going into the event processing loop and waiting for mouse and keyboard events.

In a menu, add it to the CleanUp code snippet. Select General Options from the View menu then click the Cleanup... tick box. An edit window will open behind the dialog; click OK to close the dialog window and the CleanUp edit window will remain:

If you have a program as the main element of your project then add the line immediately after you have set up the user interface by loading a form or menu.

One last thing to remember

This will start the event processing loop but we need to stop the loop to close the application. Otherwise you'll hit the second most-common problem:

Use the Clear Events command to stop the event-processing loop. Execution will continue from the line following the Read Events command.

More details on being unable to quit FoxPro .

Access Tips

FoxPro Tips

General Tips

 

Related Items

Distributing a VFP 8 executable

Distributing the executable and support files for a Visual FoxPro application

Read More

Cannot quit Visual FoxPro

How to fix the 'Cannot quit Visual FoxPro' error message

Read More

Visual FoxPro Tutorial - Build an executable

Visual FoxPro Tutorial - Build a Windows executable from a Foxpro project

Read More