The block contains a simple or structured statement that is executed when the program runs. In most programs, 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. (Every project has an Application variable that holds an instance of TApplication, TWebApplication, or TServiceApplication.) The block can also contain declarations of constants, types, variables, procedures, and functions; these declarations must precede the statement part of the block.
Program structure and syntax:
Overview
Unit structure and syntax: Overview
Unit references and
the uses clause
Multiple and indirect
unit references
Program structure and syntax:
Overview
块就是程序运行时将被执行的一个简单语句(如赋值、调用对象实例的方法等)或结构化的语句(如循环控制等)。在大部分程序(这里特指program)中,块由一组由保留字begin和end扩起来的混合语句组成,这些混合语句通常只是对工程中Application对象的方法进行简单调用。(每个工程都有一个Application变量,用于保存TApplication、TWebApplication、或TServiceApplication其中之一的实例。)块也可以含有各种声明,如常量、类型、变量、过程以及函数等,但这些声明必需位于块中语句部分之前(就象传统的Pascal编程中主程序的结构)。
编者注
一般情况下不要手工编辑工程文件,IDE会自动维护该文件的源代码,因此建议将应用程序的逻辑控制科学合理地分布到各单元中。如果确实需要在工程文件中添加一些特别的程序逻辑(如在调用Application对象的方法之前检查应用程序实例是否已经在运行中,以便决定是否加载新的应用程序实例)时,也应当尽量将语句封装在过程、函数或对象实例中,并且这些过程、函数或对象的声明和定义也不要置于工程文件中,在工程中仅根据需要进行简单调用即可。如若不然,那么工程文件将显得臃肿,而且逻辑结构也欠清晰。