Include File)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.