xHarbour Reference Documentation > Preprocessor Reference xHarbour Developers Network  

#include

Inserts the contents of a file into the current source code file.

Syntax

#include "<fileName>"

Arguments

<fileName>
This is the name of the file to insert into the file which contains the #include directive. The file name must be enclosed in double quotes.

Description

The #include directive instructs the preprocessor to insert the contents of the file <fileName> into the currently processed source file, passing the merged result to the compiler. <fileName> is the name of the include file, and can contain full path information. If no path is specified with <fileName>, the preprocessor searches for this file in the following locations and order:

1. the current directory.

2. the directory specified with the /i compiler switch.

3. the list of directories specified with the SET INCLUDE= environment variable.

Include files, often also referred to as Header files, have the CH extension in xHarbour. They are generally used to collect preprocessor directives. This way, directives can be maintained in one central place only. The #include directive is then used to make directives available for many PRG source code files.

Header files are only included to source code files that contain the #include directive. An exeption is the STD.CH file or the file specified with the /u compiler switch, which are included in all PRG files.

An include file may contain the #include directive so that one header file can include the next. This chained inclusion, however, is limited to a series of 15 files, each of which includes a new one.

By using the -u+<filename> compiler switch you may "force" a header file to be included, as if the source to be compiled has #include "<filename>" as it's first line.

Unless you use the -u (by itself) compiler switch, all source files are compiled with the set of default rules (comparable to CA-Clipper's std.ch file) loaded.

Info

See also:#command | #translate, #define
Category: Preprocessor directives

Example

// The example illustrates inclusion of a file required for
// declaring classes with xHarbour.

   #include "hbclass.ch"

   PROCEDURE Main
      LOCAL obj := MyClass():new( "Hello World" )

      obj:display()

      obj:value := "Hi there"

      obj:display()
   RETURN

   CLASS MyClass
      EXPORTED:
      DATA value
      METHOD new( cString ) CONSTRUCTOR
      METHOD display
   ENDCLASS

   METHOD new( cString ) CLASS MyClass
      ::value := cString
   RETURN self

   METHOD display CLASS MyClass
     ? ::value
   RETURN self

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe