VFP Tutorial - Build an Executable

[Project Manager in Visual FoxPro] The last stage in the tutorial is to build an executable program. For this step we need the FoxPro Project Manager back on the screen. If you are very careful with the mouse then you can drag the Manager down from the toolbar but it is very easy to drag a single tab instead of the whole manager. Being able to drag a tab off the toolbar is a useful feature during form design but it's not what we want to do at this stage. The easiest way to undock the Project Manager is to right-click on the docked manager and select Undock from the menu that appears.

Click the Build... button to display the project Build options.

Build Options

The standard version of Visual FoxPro lets you build executables and DLLs which can be freely distributed without paying additional licence fees. Select the Win32 Executable option and select the Display Errors tick box. Then click OK to build the executable.

[Options to build an executable in Visual FoxPro] You will be asked for the name of the executable. The default is for the executable to have the same name as the project and to be in the same directory but you can override both these options.

If you have Set Safety On and the project has been built before then you will be asked whether you want to overwrite the existing file.

The FoxPro development environment is not a verbose one. The cursor will change to an hourglass when the build starts and you may see progress messages flickering in the Status Bar as the build proceeds but that is all that will happen. There will be no message to say that the build has succeeded. If the cursor returns to normal without there having been any error messages then the build will have succeeded.

Running the executable

You can run the executable from within the FoxPro development environment by selecting Do from the Program menu or by typing Do Cd.Exe from the Command Window.

If you try to run the executable from outside the development environment then you will find that it just flashes on the screen and then disappears. This is because Visual Foxpro is event-driven. We need to start the event-processing loop to tell FoxPro to start looking for mouse and keyboard events as soon as the form is displayed.

Open the form from the Project Manager and double-click on the surface of the form itself. An edit window for the Load event of the form will open. We want to put some code into the Activate event so click on the combo box showing 'Load' and pick 'Activate' from the list of events. Type the following code into the edit window for the Activate event:

Read Events

This will start the event processing loop so that the program will monitor and respond to events. In order to close the application we need to stop the loop when the form closes. Double-click on the form's Close button and add an extra line to the program code in its Click event so that it reads:

Thisform.Release()
Clear Events

Save and close the form and click the Build button in the Project Manager to build the executable again. Close the FoxPro Development Environment altogether, navigate to the newly-built executable file in Windows Explorer, and run the executable by double-clicking on it. Click the Close button and check that it does indeed close the form and the application correctly.

This is a common problem when beginning FoxPro development and our site has more details on stopping and starting Fox's event-handling loop.

Distributing a Visual FoxPro executable

There are two ways of distributing a FoxPro application and both are beyond the scope of this tutorial. One is to use the VFP Setup Wizard (or InstallShield Express in later versions). The other is to just copy the files required to the user's PC. The files are listed in the FoxPro help system (and on our site at foxfiles.html).

The easiest method is to just copy all these files to the same folder as the executable program. A standard FoxPro executable does not use the same DLLs as any other Micosoft applications so distribution is usually very straightforward and we do not suffer the "DLL Hell" familiar to other developers.

FoxPro distribution requires no royalties. Once you have built your executable you can distribute as many copies of the program as you like. There is no limit on the number of people who can use it and no per-seat licencing required for the users. This ease of distribution makes Visual FoxPro a very effective tool for building custom databases.

Other platforms

Visual FoxPro 9 will run under Windows 7, Vista and XP.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If, Else and EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More