The program heading specifies the
program’s name. It consists of the reserved word program, followed by a
valid identifier, followed by a semicolon. The identifier must match the
project file name. In the previous
example, since the program is called Editor, the project file should be
called EDITOR.dpr.
In standard Pascal, a program
heading can include parameters after the program name:
program
Calc(input, output);
Borland’s Object Pascal compiler ignores these parameters.
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、有效标识符、分号。程序首部指定程序名。用于标识程序名的标识符应当与工程文件名相匹配。在前面的例子(程序结构和语法:概述)中,由于程序名叫Editor,所以相应的工程文件的文件名应为EDITOR.dpr(大小写不敏感)。
在标准Pascal中,程序首部还可以在程序名后含有参数,例如:
program
Calc(input, output);
Borland的Object Pascal编译器将忽略这些参数。
相关主题
编者注
程序名中的参数
尽管Object Pascal对于程序名中含有参数的情况可以编译并且正常运行,但开发者无法获得参数的内容,因为实质上编译器仅仅把这些参数当作一般注释而忽略了。例如,下面的程序首部尽管有效,但在程序的语句中却无法访问参数(编译器将报告错误:Undeclared identifier: ‘A’,即未声明的标识符):
program
MyTest(A, B);
...
begin
...
if A = 6
then begin
end;
...
end.
运行Windows程序可以根据需要传递参数,对于使用Borland开发工具用Object Pascal语言建立的应用程序,要在运行时传递参数,可以用Object Pascal提供的其他途径实现。详细信息可以参阅“Delphi 6 Help -> Visual Component Library Reference”中CmdLine、ParamStr、ParamCount等帮助主题。
Object Pascal代码编写习惯
用Object Pascal编程,开发者可以根据需要在几乎任何位置添加注释,前提是不要将保留字、标识符完整的单词(字)等断开。例如,你可以将程序首部写成:
program //保留字
Project1 {程序名,对应于文件Project1.dpr}
; (* 不可缺少的分号 *)