Structuring a Program as a Main File

If you use a program (.prg) file as the main file in your application, you must be sure that it includes commands to handle the tasks associated with major application tasks. The main file doesn't have to issue commands directly to accomplish all the tasks. For example, it is common to call procedures or functions to handle tasks such as initializing the environment and cleaning up.

Note   If you used the Application Wizard and allowed it to create the program Main.prg, you can modify the program the wizard created instead of creating a new one. The wizard uses a special class to define an object for the application. The main program includes sections to instantiate and configure the object.

To build a simple main program

  1. Initialize the environment by opening databases, declaring variables, and so on.
  2. Establish the initial user interface by calling a menu or form.
  3. Establish the event loop by issuing the READ EVENTS command.
  4. Issue CLEAR EVENTS command from a menu (such as an Exit command) or a button (such as an Exit command button). The main program shouldn't issue this command.
  5. Restore the environment when the user quits the application.

For example, your main program might look like this:

Code Comments
DO SETUP.PRG
Call program to set up environment (store values in public variables)
DO MAINMENU.MPR
Display menu as initial interface
READ EVENTS
Establish event loop. A different program (such as Mainmenu.mpr must issue a CLEAR EVENTS command)
DO CLEANUP.PRG
Restore environment before quitting

See Also

Controlling the Event Loop | Adding Files to a Project | Compiling an Application | Application Architecture | Setting the Starting Point | Initializing the Environment