#INCLUDE
<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > Script structure > Pre Parsing directives > #INCLUDE |
Description
Instruct the interpreter to read a text file from disk and treat it as an integral part of the source code.
Syntax
#INCLUDE [ONCE] "FileName" [AS COMMENT]
Returns
None
Parameters
Remarks
When parser encounters an #INCLUDE statement, it reads "FileName" from disk and attach the included file inside main script. The result is the same as if the contents of the included file were physically present within the main script. This allows large source files to be broken into smaller "units" that are more manageable.
"FileName" can have a full or relative path. Relative paths are always considered relative to the main script.
If no path is specified, main script path is assumed.
Optional ONCE clause can be specified. If ONCE will be specified, before including "FileName", interpreter will check if "FileName" has already been included. If yes, "FileName" will not be included again.
Including more than once a file can have impredictable results. If the included file contains user functions or variable declarations, a duplicate symbol runtime error will occur.
The following meta variables are supported inside FileName:
Name |
Meaning |
%APP_PATH% |
Insert thinBasic installation path |
%APP_SOURCEPATH% |
Insert current script path |
%APP_INCLUDEPATH% |
Insert thinBasic standard include path |
%CSIDL_ADMINTOOLS %CSIDL_ALTSTARTUP %CSIDL_APPDATA %CSIDL_BITBUCKET %CSIDL_CDBURN_AREA %CSIDL_COMMON_ADMINTOOLS %CSIDL_COMMON_ALTSTARTUP %CSIDL_COMMON_APPDATA %CSIDL_COMMON_DESKTOPDIRECTORY %CSIDL_COMMON_DOCUMENTS %CSIDL_COMMON_FAVORITES %CSIDL_COMMON_MUSIC %CSIDL_COMMON_PICTURES %CSIDL_COMMON_PROGRAMS %CSIDL_COMMON_STARTMENU %CSIDL_COMMON_STARTUP %CSIDL_COMMON_TEMPLATES %CSIDL_COMMON_VIDEO %CSIDL_CONTROLS %CSIDL_COOKIES %CSIDL_DESKTOP %CSIDL_DESKTOPDIRECTORY %CSIDL_DRIVES %CSIDL_FAVORITES %CSIDL_FLAG_CREATE %CSIDL_FONTS %CSIDL_HISTORY %CSIDL_INTERNET %CSIDL_INTERNET_CACHE %CSIDL_LOCAL_APPDATA %CSIDL_MYDOCUMENTS %CSIDL_MYMUSIC %CSIDL_MYPICTURES %CSIDL_MYVIDEO %CSIDL_NETHOOD %CSIDL_NETWORK %CSIDL_PERSONAL %CSIDL_PRINTERS %CSIDL_PRINTHOOD %CSIDL_PROFILE %CSIDL_PROGRAM_FILES %CSIDL_PROGRAM_FILES_COMMON %CSIDL_PROGRAMS %CSIDL_RECENT %CSIDL_SENDTO %CSIDL_STARTMENU %CSIDL_STARTUP %CSIDL_SYSTEM %CSIDL_TEMPLATES %CSIDL_WINDOWS |
%CSIDL_* meta statements info: https://msdn.microsoft.com/it-it/library/windows/desktop/bb762494(v=vs.85).aspx
Those meta statements will be resolved using SHGetFolderLocation function |
Meta variables are place holders that will be replaced with relevant values at script run-time.
Optional AS COMMENT clause at the end of #INCLUDE statement instructs pre parser to not use include file in parsing process. This directive is mainly used in case you want to add documentation files.
"FileName" can contains ? or * in order to specify a file mask. This option can be useful when:
•more than one files are to be included
•dynamically load files present in a directory (plug-in idea)
•other dynamic reasons
You can specify the file to be included using a URL via HTTP or HTTPS instead of a local pathname. See example below.
Restrictions
This directive is a pre parsing directive. It means all #INCLUDE statements will be solved before starting script execution.
See also
Examples
#INCLUDE ONCE "Config.inc"
#INCLUDE ONCE ".\Includes\DB.inc"
#INCLUDE ONCE ".\Includes\Theme.inc"
#INCLUDE ONCE ".\Includes\Header.inc"
#INCLUDE ONCE ".\Includes\Footer.inc"
#INCLUDE "object_*.tbasic"
#INCLUDE "%CSIDL_LOCAL_APPDATA\MyIncludes\object_*.tbasic"
#INCLUDE ONCE "https://raw.githubusercontent.com/petrSchreiber/uniTest/master/uniTest.tbasicu"