Bagikan melalui


#INCLUDE Preprocessor Directive

Tells the Visual FoxPro preprocessor to treat the contents of a specified header file as if it appeared in a Visual FoxPro program.

#INCLUDE FileName

Parameters

  • FileName
    Specifies the name of the header file that is merged into the program during compilation.

    You can include a path with the header file name. When you include a path with the header file name, Visual FoxPro searches for the header file only in the specified location.

    If you do not include a path with the header file name, Visual FoxPro searches for the header file in the default Visual FoxPro directory, and then along the Visual FoxPro path. The Visual FoxPro path is specified with SET PATH.

Remarks

You can create header files containing preprocessor directives and then use #INCLUDE to merge the contents of the header file into a program when the program is compiled. The contents of the header file are inserted into the program during compilation at the point where #INCLUDE appears in the program.

Only the #DEFINE ... #UNDEF, #IF ... #ENDIF, and #INCLUDE preprocessor directives are recognized in a header file. Comments and Visual FoxPro commands included in a header file are ignored.

A program can contain any number of #INCLUDE directives. These directives can appear anywhere within the program. Putting #INCLUDE directives in header files makes it possible for you to nest #INCLUDE directives.

Header files typically have an .h extension, although they can have any extension. A Visual FoxPro header file, Foxpro.h, is included. It contains many of the constants described throughout this documentation.

Example

In the following example, two files are used: Const.h, a header file, and Myprog.prg, a program file. The header file contains several #DEFINE directives that create compile-time constants. The program file uses #INCLUDE to merge the Const.h header file at compilation, making the compile-time constants in the header file available to the program.

** Header file CONST.H ** #DEFINE ERROR_NODISK 1 #DEFINE ERROR_DISKFULL 2 #DEFINE ERROR_UNKNOWN 3

** Program file MYPROG.PRG ** #INCLUDE CONST.H

FUNCTION chkerror
PARAMETER errcode
  DO CASE
  CASE errcode = ERROR_NODISK
  ?"Error - No Disk"
  CASE errcode = ERROR_DISKFULL
  ?"Error - Disk Full"
  CASE errcode = ERROR_UNKNOWN
  ?"Unknown Error"
  ENDCASE
RETURN

See Also

#DEFINE ... #UNDEF Preprocessor Directive | #IF ... #ENDIF Preprocessor Directive | #IFDEF | #IFNDEF ... #ENDIF Preprocessor Directive | #INCLUDE Preprocessor Directive