Use #INCLUDE to Add Header Files to a Visual FoxPro ProjID: Q131475 3.00 WINDOWS The information in this article applies to:
SUMMARYBy using the #INCLUDE directive, you can instruct Visual FoxPro to include the contents of another file such as a header file (.H file) in your code during compilation. Header files have useful items such as standard constants that you can use in your Visual FoxPro code. This ability has existed in the C programming language. Now it is also available to Visual FoxPro developers.
MORE INFORMATION
Benefits of Using #INCLUDECoding problems can be minimized when the #INCLUDE generator directive is used to include header files. Constants can be given values once in the header file, and these constants can be used anywhere in FoxPro code. By definition, the value of PI is 3.14. If a named constants header file is created with a #DEFINE for PI, the word PI could be used rather than typing 3.14. Using the named constant, Visual FoxPro replaces all occurrences of PI with 3.14 at compile time. Using English words like PI in code improves readability and can make localization for non-English countries easier. For example, a single constants file could be created that contains application messages as follows:
Then, use CANCELENTRY in your Visual FoxPro code. To translate your program
for a different country, all you need to do is translate a copy of the
constants file into the different language. No changes to your Visual
FoxPro code are necessary.
Example One: COMMON.HA Named Constants file (FOXPRO.H) comes with Visual FoxPro. It contains the named constants for most Visual FoxPro functions. You can extend this concept of named constants even further by creating a COMMON.H file to define a number of standard types of constants such as the character values required for a carriage return/linefeed. The following sample header file demonstrates this concept: * COMMON.H *-- ASCII If you use #INCLUDE to include this COMMON.H file in your Visual FoxPro
project, you can use the text CRLF at any point in your program code where
a carriage return/linefeed combination is needed. You no longer need to
type CHR(13)+CHR(10). While either choice (CRLF or CHR(13)+CHR(10)) is
valid, if a defined constant should change values, it need only be changed
in a single location for that change to be reflected at all locations in
your code where the constant is referenced.
Example Two: TESTFILE.PRGBuilding on the COMMON.H file, the following code provides a simple demonstration of the use of a COMMON.H file and constants referenced in code: *-----------------------------------------------------------* *-----------------------------------------------------------*
#INCLUDE "COMMON.H" && Use definitions from COMMON.H file
ACTIVATE SCREEN CLEAR ? 'Line 1'+CRLF+'Line 2' =TestUDF() FUNCTION TestUDF RETURN
*-----------------------------------------------------------*
*-----------------------------------------------------------* *-----------------------------------------------------------*
*-- ASCII
*-- Header files
#INCLUDE "FOXPRO.H" ** If not in current directory, you
*----------------------------------------------------------*
Example Three: Using FOXPRO.H that Comes with Visual FoxProHere's another example use of named constants in code. As found in the FOXPRO.H file, the following constants for the MessageBox function can be used in place of the numeric equivalents. This list has been abbreviated for space considerations: *-- Function Parameters *-- MessageBox parameters *-- MsgBox return values
Given the above definitions, a sample dialog box written without the named
constants might read as follows:
The nDialogType code could be recast using named constants as this:
Both ways are equally valid, but by using words as opposed to numbers, the
code is easier to understand and maintain.
REFERENCESAdditional information about the #INCLUDE directive and related topics can be found in the Visual FoxPro Help file under the following topics:
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |