Delphi Project composition of the unit file Pas

Source: Internet
Author: User

The unit file is a Pascal source file with a . pas extension.

There are three types of cell files:

    1. Form/data modules and Frame unit files (Form/data module and frame units), typically generated automatically by Delphi.
    2. component's Unit file (component units), generated by you or Delphi.
    3. Common Unit files (general-purpose units), which have you created.

Let's take a look at the basic Pascal unit file structure.

Step1, on the main menu, selectFile | New | unit ", Delphi will create a new unit and display it in Code Editor.

Step2, let's take a look at one of the simplest Pascal units, including four keywords unit,interface,implementation , and end ;

Compare the whole unit as follows, please see the note:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 unitUnit1;interfaceuses { List of units goes here }  Windows, Messages,  SysUtils, Variants,  Classes, Graphics,  Controls, Forms, Dialogs;                { Interface section goes here }type { type关键字用来声明一个新的类型}  TMyArray = array[0..19] ofByte;                { 声明TMyArray用来代替array[0..19] of Byte}const{ const关键字用来声明常量}  AppCation = ‘Hello World‘;                { AppCation由于在interface段声明,它在单元的任何地方都可以用}var{ var关键字用来声明变量,也分interface段和implementation段}  X: Integer;  MyArry: TMyArray;                { MyArray为刚才定义的TMyArray新类型}  procedureDoSomething;                { 声明一个DoSomething过程}implementationuses{ List of units goes here }  SysUtils, Variants;var  ObjList: TObjectList;const{ BaseX,BaseY由于在implementation段声明,只能在单元内使用}  BaseX = 20;  BaseY = 200;                { 实现interface段声明的DoSomething过程}  procedureDoSomething;  begin                { Code for DoSomething goes here.}  end;                 //C++风格的注释,只能用于单行注释                (*                  相同类型注释不能嵌套                *)                {                 推荐使用的注释符号                }                { Implementation section goes here }initialization                { Initialization section goes here }  ObjList := TObjectList.Create;finalization                { Finalization section goes here }  FreeAndNil(ObjList);end.

Uses cell reference

The list of external cells referenced by a cell, where each cell must be separated by commas, and the last cell must be semicolon-delimited to indicate the end of the uses list.

Interface interface Segment

The output identifier for this unit of life, which is an item that can be accessed by other cells. The interface segment begins with interface and ends with implementation.

Implementation execution Segment

The execution segment starts with implementation, the following keyword ends, and the next keyword is usually the last keyword end of the cell. But in a unit with initialization, the next key is the initialization keyword.

The above three parts are required by the Unit unit. The next two keyword sections are optional.

Initialization unit initialization and end of Finalizaiton unit

Code used to perform startup and cleanup, any code in the initialization is executed when its unit is loaded into memory, and any code in the end segment is executed before the unit is cleaned out of memory.

You can have only one initialization segment, but not only the end segment, not the initialization segment.

Delphi Project composition of the unit file Pas

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.