内容源自Delphi XE5 UPDATE 2官方帮助《Delphi Reference》,本人水平有限,欢迎各位高人修正相关错误!

也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可QQ:34484690@qq.com

1 Program Structure and Syntax

1程序的结构和语法

A complete, executable Delphi application consists of multiple unit modules, all tied together by a single source code module called a project file. In traditional Pascal programming, all source code, including the main program, is stored in .pas files. Embarcadero tools use the file extension .dpr to designate the main program source module, while most other source code resides in unit files having the traditional .pas extension. To build a project, the compiler needs the project source file, and either a source file or a compiled unit file for each unit.

一个完整的,可执行的Delphi应用程序由多个单元模块构成。一个项目文件调用单个源代码文件并将他们捆绑在一起。每个单元保存在一个单独的文件中并分别进行编译,编译后的单元被链接到程序中。在传统的 Pascal 编程中,所有源代码,包括主程序都存储在.pas 文件中。Embarcadero工具使用一个工程文件(.dpr)来存储‘主’程序,而大部分源代码则保存在单元文件(.pas)中。要编译一个项目,编译器需要项目源文件,以及一个源文件或每个单元一个编译单元文件。

Note: Strictly speaking, you need not explicitly use any units in a project, but all programs automatically use the System unit and the SysInit unit.

注:严格来说,你不需要显式地使用任何一个项目单元,但所有程序自动使用System 单元和SysInit 单元。

The source code file for an executable Delphi application contains:

一个可执行的Delphi应用程序的源代码文件中包含:

a program heading,

一个程序头(program heading),

a uses clause (optional), and

一个 uses 子句(可选),和

a block of declarations and executable statements.

一个包含声明和命令语句的块(block)。

程序头指定程序的名称;uses 子句列出了程序引用的单元;块包含声明和命令语句。

The compiler, and hence the IDE, expect to find these three elements in a single project (.dpr) file.

当程序运行时,这些命令将被执行。IDE 期望在一个工程文件(.dpr)中找到以上三种元素。

1.1   The Program Heading

1.1    程序头

 

The program heading specifies a name for the executable program. It consists of the reserved word program, followed by a valid identifier, followed by a semicolon. For applications developed using Embarcadero tools, the identifier must match the project source file name.

程序头指定可执行程序的名称。它是程序的保留字,接着是一个有效的标识符,后面跟着一个分号。对于使用Embarcadero工具开发的程序,该标识符必须和项目源文件名匹配。

The following example shows the project source file for a program called Editor. Since the program is called Editor, this project file is called Editor.dpr.

下面的实例显示了一个叫做 Editor 的程序的项目源文件.它以关键字 program 开始,后面跟一个有效标志符(指定程序名),并以分号结束。标志符必须和工程文件名相同,在上例中,因为程序叫Editor,工程文件应该是EDITOR.dpr。

program Editor;

  uses Forms, REAbout, // An "About" box

       REMain;         // Main form

  {$R *.res}

  begin

   Application.Title := 'Text Editor';

   Application.CreateForm(TMainForm, MainForm);

   Application.Run;

  end.

The first line contains the program heading. The uses clause in this example specifies a dependency on three additional units: Forms, REAbout, and REMain. The $R compiler directive links the project's resource file into the program. Finally, the block of statements between the begin and end keywords are executed when the program runs. The project file, like all Delphi source files, ends with a period (not a semicolon).

第一行包含该程序的程序头。例子中的uses子句指定它与其它三个units的依赖关系:Forms, REAbout, 和 REMain。$R编译指令链接项目的资源文件到程序中。最后,当程序运行时会执行begin和end之间的语句块。和所有源文件一样,工程文件以一个.句点(不是分号)结束。

Delphi project files are usually short, since most of a program's logic resides in its unit files. A Delphi project file typically contains only enough code to launch the application's main window, and start the event processing loop. Project files are generated and maintained automatically by the IDE, and it is seldom necessary to edit them manually.

Delphi工程文件通常很短,因为绝大部分的程序逻辑位于单元文件中。一个Delphi项目文件通常只包含足够的代码以启动应用程序的主窗口,并启动事件处理循环。工程文件是由IDE自动产生并自动维护的,很少需要手工编辑。

In standard Pascal, a program heading can include parameters after the program name:

在标准Pascal中,程序头的程序名称后面包括参数:

program Calc(input, output);

Embarcadero's Delphi ignores these parameters.

Embarcadero的Delphi忽略这些参数。

In RAD Studio, the program heading introduces its own namespace, which is called the project default namespace.

在RAD Studio中,程序头引入自己的命名空间,这就是所谓的默认的命名空间。

1.2   The Program Uses Clause

1.2程序的uses 子句

The uses clause lists those units that are incorporated into the program. These units may in turn have uses clauses of their own. For more information on the uses clause within a unit source file, see Unit References and the Uses Clause, below.

uses 子句列出了共同构成程序的单元,这些单元可能包含自己的uses 子句。关于uses 子句,请参考单元引用和uses 子句。

The uses clause consists of the keyword uses, followed by a comma delimited list of units the project file directly depends on.

uses子句中包含关键字uses,其后的项目文件units列表用,进行分隔。

1.3 The Block

1.3

The block contains a simple or structured statement that is executed when the program runs. In most program files, the block consists of a compound statement bracketed between the reserved words begin and end, whose component statements are simply method calls to the project's Application object. Most projects have a global Application variable that holds an instance of Vcl.Forms.TApplication, Web.WebBroker.TWebApplication, or Vcl.SvcMgr.TServiceApplication. The block can also contain declarations of constants, types, variables, procedures, and functions; these declarations must precede the statement part of the block. Note that the end that represents the end of the program source must be followed by a period (.):

块包含一个简单语句或结构语句,程序运行时将执行它。在大多数程序中,块包含一个复合语句,它(复合语句)由关键字begin 和end 括起来,其中的命令只是简单调用Application 对象的方法。大多数工程都有一个全局的Application 变量,它是Vcl.Forms.TApplication, Web.WebBroker.TWebApplication, 或者 Vcl.SvcMgr.TServiceApplication的一个实例。块也可以包含常量、类型、变量、过程和函数的声明,它们必须位于(块中)命令语句的声明部分(前面)。需要注意的是,表示源程序结尾的end后必须跟一个句点(.):

begin

  .

  .

  .

end.

Delphi XE5教程5:程序的结构和语法的更多相关文章

  1. Delphi XE5教程6:单元的结构和语法

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...

  2. Delphi XE5教程4:程序和单元概述

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误!也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可 ...

  3. Delphi XE5教程3:实例程序

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...

  4. Delphi XE5教程2:程序组织

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...

  5. Delphi XE5教程1:语言概述

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...

  6. Delphi XE5教程11:Tokens

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误!也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可 ...

  7. Delphi XE5教程9:基本语法元素

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误!也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可 ...

  8. Delphi XE5教程8:使用Delphi命名空间

    // Project file declarations... //项目文件声明… program MyCompany.ProjectX.ProgramY; // Unit source file d ...

  9. Delphi XE5教程7:单元引用和uses 子句

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...

随机推荐

  1. 通过cagradientLayer类封装uiimageview动画色度差

    #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, EcolorDirectionType) { EcolorDirectionUp, / ...

  2. Java基础知识强化之IO流笔记81:NIO之 DatagramChannel

    1. Java NIO中的DatagramChannel是一个能收发UDP包的通道.因为UDP是无连接的网络协议,所以不能像其它通道那样读取和写入.它发送和接收的是数据包. 2. DatagramCh ...

  3. android系统启动时自动运行自己的程序

    android系统在Manifest.permission中有这样一条RECEIVE_BOOT_COMPLETED的定义,当你自己的程序加 入这个权限后,就可以在系统启动完毕后收到一条系统的广播,这个 ...

  4. CALayer 简单操作和实际应用

    1.CALayer //每一个UIView,都存在一个CALayer.(主层) //CALayer的功能 描边,圆角,阴影... //CALayer 属于QuartzCore绘图框架 //明明有UIC ...

  5. 管理后台-第二部分:Custom sections in Umbraco 7 – Part 2 the views(翻译文档)

    在上一篇文章中我们讨论了怎样在我们Umbraco7.0版本中去添加一个新的自定义的应用程序(或部分)和如何去定义一个树.现在我将给你展示你改何如添加视图,来使你的内容可以做一些更有意义的事情. The ...

  6. Linux 驱动分类 与访问技术

    驱动开发概述 1.驱动分类 1.1 常规分析法 1.1.1  字符设备  字符设备是一种按字节来访问的设备,字符驱动则负责驱动字符设备,  这样的驱动通常实现open, close, read和wri ...

  7. Laravel 清空配置缓存

    清空配置缓存 php artisan cache:clear php artisan config:clear

  8. 转 【O2O案例】汽车后市场垂直化电子商务:平业模式解析

    核心提示:一.商业模式简介.汽车后市场垂直化电子商务是我在2010年初开始筹划,起因是在淘宝工作期间运营汽车类目后遇到很多问题无决,由于 一.商业模式简介. 汽车后市场垂直化电子商务是我在2010年初 ...

  9. Meta也很强

    <!--http-equiv 必要属性--> <meta http-equiv="Content-Type" content="text/html; c ...

  10. Table of Contents - 设计模式

    设计原则 OCP - 开闭原则 SRP - 单一职责原则 DIP - 依赖倒置原则 ISP - 接口隔离原则 LSP - 里氏替换原则 LoD - 迪米特法则 创建型模式 工厂方法模式 抽象工厂模式 ...