The
compiler expects to find Pascal source code in files of three kinds:
·unit source files
(which end with the .pas extension)
·project files
(which end with the .dpr extension)
·package source
files (which end with the .dpk extension)
Unit source files contain most of the code in an application. Each application has a single project file and several unit files; the project file which corresponds to the main program file in traditional Pascal organizes the unit files into an application. Borland development tools automatically maintain a project file for each application.
If you are compiling a program from the
command line, you can put all your source code into unit (.pas) files. But if
you use the IDE to build your application, you must have a project (.dpr) file.
Package source files are similar to project files, but they are used to construct special dynamically linkable libraries called packages. For more information about packages, see Dynamic-link libraries and packages.
Program organization: Overview
Other files used to build applications
Other files used to build applications
译文
编译器在编译程序时将希望找到以下三种Pascal源文件:
· 单元源文件(扩展文件名为.pas)
· 工程文件(扩展文件名为.dpr)
· 包源文件(扩展文件名为.dpk)
其中,单元源文件包含了应用程序的大不分代码。每个应用程序都有一个单独的工程文件和几个单元文件;工程文件相当于传统Pascal中的主程序,它将单元文件组织到应用程序中。Borland开发工具为每个应用程序自动管理工程文件。
如果以命令行的方式编译程序,那么可以将所有的源代码置于单元(.pas)文件中。但如果要在集成开发环境中建立应用程序,则必需有一个工程(.dpr)文件。
包源文件与工程文件类似,只是包源文件用语构造特殊称为“包”的动态链接库。关于包的更多信息,见库和包(根据链接目标内容来看,原文应为Libraries and packages)。
编者注
尽管编译器会根据uses子句查找相关单元相应的.pas源文件,但这并不意味没有相应的.pas文件就无法成功编译。事实上,如果没有找到源文件,那么编译器将会查找相应的.dcu文件,这类文件是.pas源文件编译生成的文件。在Delphi中,开发者需要大量使用VCL提供的资源,因此在uses子句中会有很多单元是Delphi预先提供的,在编译时Delphi并不对这些单元进行重新编译,而是直接利用相应的.dcu文件编译生成最终的应用程序。这些.dcu文件位于目录“<Delphi>\Lib”中。至于目录“<Delphi>\Source\vcl”中的.pas文件,是提供调试和参考的,Delphi不会对这些源文件进行编译,除非开发者强制将其中某些被使用的单元放置在当前工程所在的目录中时(因此可以通过这样的途径修改VCL从而只影响当前工程而不影响其它工程)。