Identifiers
denote constants, variables, fields, types, properties, procedures, functions,
programs, units, libraries, and packages. An identifier can be of any length,
but only the first 255 characters are significant. An identifier must begin
with a letter or an underscore (_) and cannot contain spaces; letters, digits,
and underscores are allowed after the first character. Reserved words cannot be
used as identifiers.
Since
Object Pascal is case-insensitive, an identifier like CalculateValue
could be written in any of these ways:
CalculateValue
calculateValue
calculatevalue
CALCULATEVALUE
On Linux, the only identifiers for which case is important are unit names. Since unit names correspond to file names, inconsistencies in case can sometimes affect compilation.
When you
use an identifier that has been declared in more than one place, it is
sometimes necessary to qualify the identifier. The syntax for a
qualified identifier is
identifier1.identifier2
where identifier1 qualifies identifier2.
For example, if two units each declare a variable called CurrentValue,
you can specify that you want to access the CurrentValue in Unit2
by writing
Unit2.CurrentValue
Qualifiers
can be iterated. For example,
Form1.Button1.Click
calls the Click method in Button1
of Form1.
If you
don’t qualify an identifier, its interpretation is determined by the rules of
scope described in Blocks and
scope.
Fundamental syntactic elements:
Overview
标识符用于表示常量、变量、域、类型、属性、过程、函数、程序、单元、库和包等。尽管标识符的长度可以是任意的,但只有前255个字符是有意义的。标识符必需以字母或下划线(_)开始(即标识符的第一个字符必需是字母或下划线),并且标识符中不能包括空格。在标识符的第一个字符之后,字母、数字、下划线都是允许的。保留字不能作为标识符使用。
Object
Pascal语言对字符大小写是不敏感的。例如,标识符CalculateValue可以被写成以下几种方式:
CalculateValue
calculateValue
calculatevalue
CALCULATEVALUE
在Linux中,标识符作为单元名时大小写比较重要。由于单元名与相应的源文件名是相匹配的,因此大小写不一致有时会影响编译。
在使用的标识符在多于一个单元中都有声明时,有时有必要限制标识符。限制标识符的语法如下:
identifier1.identifier2
这里的identifier1限制了identifier2。例如,如果两个单元中都声明了名为CurrentValue的变量,那么可以通过对标识符进行限制来指定访问Unit2中的CurrentValue,写成
Unit2.CurrentValue
此外,Object Pascal允许迭代限制。例如语句:
Form1.Button1.Click
调用了Form1中Button1的Click方法。
如果不对标识符进行限制,那么编译器将根据作用域规则确定对该标识符的解释,见块和作用域。