$INCLUDE Command

Top  Previous  Next

The $INCLUDE preprocessor command allows reading header files and even other source files into the source file being compiled. Header files have a .inc extension in Emergence BASIC and are traditionally used for API definitions, constants, TYPE definitions, and COM declarations.

The $INCLUDE command excepts a string containing the name of the file to be included. The string is not a constant and the normal rules for specifying paths do not apply. If a full path is not specified the include directory will be searched for the file. The include directory is located just off the main installation directory for Emergence BASIC, which if you chose defaults during installation would be:

C:\Program Files\EBDev\Include\

You are free to store any include file there you wish to aid in developing programs. The IDE knows what include files are and after creating them choose Save As.. from  the File menu and choose "EBASIC Include Files (*.inc)" from the drop down file types box.

Example include statements:
 

$INCLUDE "ishelllink.inc"
$INCLUDE "c:\myIncludes\bitmaps.inc"

As noted above the quoted string is not a constant and does not need the double backslash in the paths like a constant string would in your programs.

Notes, caveats, warnings

Any errors in an include file will correctly show the file and line number in the build window.

All include statements should be placed as the first lines in your source file. The contents of the included file are inserted at the point the $INCLUDE statement appears.

While you can include other source files containing subroutines keep in mind the above warning. The $INCLUDE statement is a preprocessor command and the compiler will attempt to inject and compile anything in the included file at the point of insertion. For example this would be a bad idea and will result in many errors:

IF something

$INCLUDE "file.eba"

ENDIF

The correct method is to use conditional compiling at the beginning of your source file.
 

$IFDEF SHAREWARE
   $INCLUDE "sharewaredefs.inc"
$ELSE
    $INCLUDE "fulldefs.inc"
$ENDIF

Include file may be nested up to 100 levels deep. That is one include file can include others recursively up to 100 times. It is very unusual to have more than two levels of include file nesting though.