内容源自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. OC 和 swift 小结

    1 什么是 OC 语言? OC 语言即面向对象语言,它扩展了 ANSI C 语言,将 SmallTalk 式的消息传递机制加入到 ANSI C 中.它是苹果 OS 和 iOS 以及相关的 API,Co ...

  2. 要检测两个C文件的代码的抄袭情况

    将抄袭部分输出 如果只是变量名替换了 也算抄袭 如果输入了一些干扰代码以防止被检测出来 也算抄袭专业程序代写c++程序代写

  3. maven安装仓库中不存在的jar包

    这里以ojdbc6.jar作为案例 首先我的ojdbc6.jar放在D盘的根目录D:\ojdbc6.jar 然后我们打开cmd命令窗口,运行命令:mvn install:install-file -D ...

  4. 剑指Offer31 把数组排成最小的数

    /************************************************************************* > File Name: 31_SortAr ...

  5. QTREE3 spoj 2798. Query on a tree again! 树链剖分+线段树

    Query on a tree again! 给出一棵树,树节点的颜色初始时为白色,有两种操作: 0.把节点x的颜色置反(黑变白,白变黑). 1.询问节点1到节点x的路径上第一个黑色节点的编号. 分析 ...

  6. 转: 跨终端Web之Hybrid App

    转:  http://www.infoq.com/cn/articles/hybrid-app 编者按:InfoQ开设新栏目“品味书香”,精选技术书籍的精彩章节,以及分享看完书留下的思考和收获,欢迎大 ...

  7. xhtml+css基础知识1

    样式 行间样式:在标签里 <div style="width:400px; height:200px; background:red;">块</div> 内 ...

  8. 支持多浏览器的镜像反转css效果

    今天接到一个需求,通过一张图片得到其镜像对称的图片.本来说是后台处理的,但这样除了技术上难实现之外,还带来了资源消耗的问题,相当于每张图都要存储一个副本了. 只记得以前用过css的滤镜可以实现这个,但 ...

  9. JQuery Mobile + Cordova 实战一

    好的,今天给大家继续讲解 JQM 和 Cordova 的结合吧.Cordova 和 Phonegap 反正是一个东西,大家就当做一个是旧版(Phonegap)的一个是新版(Cordova)的就行.不同 ...

  10. miniui MVC datagrid数据绑定

    数据绑定 Default.cshtml <div id="datagrid1" class="mini-datagrid" style="wid ...