A file can contain any code that you do not want to appear in the primary source unit. A typical usage is to retain constants or compiler instructions, which are used in other files of a project.
Only one file is includedINCText file with the extension.INCThe extension is not a must, but a convention.
Next we will useHello, worldTo describe how to use the included files.
1,Let's create a newConsole Application, Through the menu 【File | new | others...] OpenNew itemsDialog box, and then selectConsole Application.
2,Create the defaultConsole ApplicationAnd then select 【File | save all] Save the projectProject2To an independent directory (suchC: \ inctest).
3,Start creating a new file, and choose 【File | new | others...] OpenNew itemsDialog box, and then selectText iconIn this way, a new file is created as follows:
4,Enter the following code in the newly created text file:
Const astr = 'hello, world'; {defining constant strings}
5,Then select the menu 【File | save] Save the file, but you must use it.INC ExtensionSave the file, otherwise it will be saved with the default txt extension, as shown below:
6,To use an included file, you must use it in all other units that need to use the included file.$ I compiler commandsThe Code is as follows:
Program project2; {$ apptype console} uses sysutils; {$ I test. INC} // here the $ I compilation command reference test. INC contains the file content begin writeln (astr); // astr is test. readln; end.
7,PressF9After the compilation is successful, the result is as follows:
Caution
Make sure that the code syntax in the inclusion file is correct. Otherwise, a compiler error occurs.
The above code passes the test in Delphi7.