Compiles one or more specified source files and creates an object file for each source file. There are two versions of the syntax.
COMPILE [DATABASE | FORM | CLASSLIB | LABEL | REPORT] cFileName | cFileSkeleton | ? [ALL]
COMPILE cFileName | cFileSkeleton | ? [ENCRYPT] [NODEBUG] [AS nCodePage]
Compiles one or more database (.dbc) files specified by cFileName or cFileSkeleton. Choosing DATABASE compiles source code for stored procedures that are saved with the database and stores it in an additional memo field. You can use the DATABASE option to compile stored procedures outside the Database Designer.
COMPILE DATABASE packs memo fields in the database memo file (.dct) to remove unused space from the memo file. Records marked for deletion in the database table are not removed from the table.
Compiles one or more form definition files (.scx) specified by cFileName or cFileSkeleton. Choosing FORM compiles source code for the data environment that is saved with the form and stores in an additional memo field. Visual FoxPro automatically compiles forms when they are saved in the Form Designer. You can use the FORM option to compile a form outside the Form Designer.
Form source code is stored in memo fields in the Form table. COMPILE FORM compiles the memo fields into object code and stores it in an additional memo field. Visual FoxPro executes the object code in the additional memo field when you use the DO FORM command. For more information, see DO FORM Command.
Compiles one or more visual class library (.vcx) files specified by cFileName or cFileSkeleton. Source code for a visual class library is stored in memo fields in the visual class library table. Choosing CLASSLIB compiles the memo fields into object code and stores it in an additional memo field.
Compiles one or more label definition files (.lbx) specified by cFileName or cFileSkeleton. Choosing LABEL compiles source code for the data environment saved with the label file and stores it in an additional memo field.
Compiles one or more report definition files (.frx) specified by cFileName or cFileSkeleton. Choosing REPORT compiles source code for the data environment saved with the report file and stores it in an additional memo field.
Specifies the target file to compile.
If you specify one of the listed options, the following table describes the values for cFileName that correspond to the option you choose.
Name of the database containing the stored procedures to compile.
You can compile stored procedures in a database that is not open.
Name of the form to compile.
Name of the class library to compile.
Name of the report to compile.
Name of the report to compile.
If you do not specify one of the listed options, such as FORM or REPORT, the following list shows other files you can specify for cFileName.
Specifies a set or subset of files that match a file skeleton that can contain wildcard characters such as an asterisk (*) or question mark (?).
For example, to compile all database files that begin with the letter A, use the following command:
COMPILE DATABASE A*
To compile all program files that have the .prg file name extension in the current directory or folder, use the following command:
Displays the Compile dialog box so you can browse and choose a file to compile.
For older cross-platform report (.frx) and label (.lbx) files, compiles all records for all Visual FoxPro platforms in the form table and is available only for the REPORT and LABEL options. If you omit ALL, only records for the current Visual FoxPro platform are compiled.
For example, suppose you have an .frx file containing only Windows and Macintosh records. When executing the COMPILE command on a computer with Windows, omitting ALL compiles only Windows records.
Encrypts compiled Visual FoxPro program files and is not available when using the DATABASE, FORM, CLASSLIB, LABEL, and REPORT options. ENCRYPT prevents access to the original source programs. For additional source code protection, always include this option when compiling programs intended for distribution.
Reduces the size of the compiled file by two bytes per source file line and is not available when using the DATABASE, FORM, CLASSLIB, LABEL, and REPORT options.
The two bytes reduced in the compiled file are a reference to the corresponding line in the source file. Removing these two bytes does not affect the program's performance, but it does reduce the compiled file size and conserves disk space.
When you include NODEBUG, you cannot view execution of the program in the Trace window or return the source code for a line that causes an error by using MESSAGE(1). For more information, see.
- AS nCodePage
Specifies the code page for which a program file is compiled and is not available when using the DATABASE, FORM, CLASSLIB, LABEL, and REPORT options. The compilation code page you specify overrides the global compilation code page specified with SET CPCOMPILE.
Visual FoxPro executes only object files, so if a source file has not been compiled, it is automatically compiled into an object file when you run the program. The source file remains unchanged. A separate compiled object file is created with the same root name as the source file, but with a different extension. The following table lists example source file extensions and compiled file extensions for each file type.
|File type||Source extension||Compiled extension|
The compiler detects any syntax errors in the source file. If SET LOGERRORS is set to ON when the file is compiled, Visual FoxPro saves compilation error messages to a text file. The error log file has the same root name as the compiled file and has an .err file name extension. If SET LOGERRORS is set to OFF, the error log file is not created. For more information, see.
If a form has an #INCLUDE header (.h) file, and the .h file is moved from its original directory, a compilation error occurs and is listed in the error log (.err) file. You can run the form, but if you modify it, you cannot save it until you correct the path to the .h file.
To correct the path for a moved header (.h) file
Open the form using the MODIFY FORM command.
On the Form menu, choose Include File.
In the Include File dialog box, browse to or type the new path for the .h file.
For more information, see, , and .
The following example uses CLOSE DATABASES to close all open databases and uses COMPILE DATABASE to compile all the stored procedures in the Visual FoxPro sample database, TestData.dbc.
CLOSE DATABASES COMPILE DATABASE (HOME(2) + 'Data\TestData')