内容源自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。

  1. program Editor;
  2.  
  3. uses Forms, REAbout, // An "About" box
  4.  
  5. REMain; // Main form
  6.  
  7. {$R *.res}
  8.  
  9. begin
  10.  
  11. Application.Title := 'Text Editor';
  12.  
  13. Application.CreateForm(TMainForm, MainForm);
  14.  
  15. Application.Run;
  16.  
  17. 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中,程序头的程序名称后面包括参数:

  1. 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后必须跟一个句点(.):

  1. begin
  2.  
  3. .
  4.  
  5. .
  6.  
  7. .
  8.  
  9. 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. KVO监听数组的变化

    #import "ViewController.h" @interface ViewController () @property(nonatomic,strong)NSMutab ...

  2. 最近在用placeholder ,是已有的,网上也有不少都是jq写的

    其实除了支持placeholder 的浏览器,其他用js 或jq实现的都不叫placeholder 效果,只能算上是获取焦点,或失去焦点时的一个placeholder 没有出生时就已经存在效果 很多人 ...

  3. putty ssh login linux

    (1) in linux $ ssh-keygen -t dsa $ cd .ssh $ cat id_dsa.pub > authorized_keys $ chmod 600 authori ...

  4. leetcode 题解: Length of Last Word

    leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...

  5. Unix系统安装MySQL-python出现UnicodeDecodeError错误解决方法

    今天装MySQL-python时候出现了这个错误: error: command ---------------------------------------- Cleaning up... Com ...

  6. Java Script基础(三) 函数

    一.JavaScript中的函数 在JavaScript中,函数类似于Java中的方法,是执行特定功能的代码块,可以重复调用.JavaScript中的函数分为两种,一种是系统函数,另一种是自定义函数. ...

  7. PHP trim()函数的一些用法

    string trim ( string $str [, string $charlist ] ) - 去除字符串首尾处的空白字符(或者其他字符) trim()函数当第二个参数为空时,默认去掉空格.制 ...

  8. Spring学习总结三——SpringIOC容器三

    一:spring容器自动装配注入 为了减少xml中配置内容,可以使用自动装配注入,代替setter注入,只需要在 bean对象配置中添加属性autoWire即可,那么在类中就会自动扫描setXXX() ...

  9. Differential Geometry之第二章曲线的局部理论

    第二章.曲线的局部理论 2.1 曲线的概念 关于非正则曲线的讨论: ,这是个非正则点(尖点),且它是非正则曲线. 直观上,间断点,孤立点,结点(交叉点),尖点是非正则点. 有记载说:当同一条曲线用不同 ...

  10. 6步图文教你优化myeclipse2014

    MyEclipse 2014优化速度方案仍然主要有这么几个方面:去除无需加载的模块.取消冗余的配置.去除不必要的检查.关闭更新. 第一步: 去除不需要加载的模块 一个系统20%的功能往往能够满足80% ...