A block consists of a series of
declarations followed by a compound statement. All declarations must occur
together at the beginning of the block. So the form of a block is
declarations
begin
statements
end
The declarations section
can include, in any order, declarations for variables, constants (including
resource strings), types, procedures, functions, and labels. In a program
block, the declarations section can also include one or more exports
clauses (see Dynamic-link
libraries and packages).
For example, in a function
declaration like
function
UpperCase(const S: string): string;
var
Ch: Char;
L: Integer;
Source, Dest: PChar;
begin
...
end;
the first line of the declaration is the function heading and all of the succeeding lines make up the block. Ch, L, Source, and Dest are local variables; their declarations apply only to the UpperCase function block and override in this block only any declarations of the same identifiers that may occur in the program block or in the interface or implementation section of a unit.
块由一系列声明和紧随声明之后的混合语句组成。所有的声明都必需出现在块的开始处。块具有如下形式:
declarations
begin
statements
end
这里的的声明delarations部分包括对变量、常量(含资源串)、类型、过程、函数、标号等的声明(声明实体的顺序是任意的)。在程序块中,声明中还可以包括一个或多个exports子句(见库和包)。
例如,对于函数声明
function
UpperCase(const S: string): string;
var
Ch: Char;
L: Integer;
Source, Dest: PChar;
begin
...
end;
第一行是函数首部,随后的所有行构成了块。Ch、L、Source和Dest都是局部变量,它们的声明仅适用于UpperCase函数块,并且在当前块中,这些局部变量代替(或忽略)所有可能出现在程序块、单元接口节或单元实现节中同名标识符的声明。