delphi 捕获源
In short, a Delphi project is just a collection of files that make up an application created by Delphi. DPR is the file extension used for the Delphi Project file format to store all the files related to the project. This includes other Delphi file types like Form files (DFMs) and Unit Source files (.PASs).
简而言之,Delphi项目只是构成由Delphi创建的应用程序的文件的集合 。 DPR是用于Delphi Project文件格式的文件扩展名,用于存储与项目相关的所有文件。 这包括其他Delphi文件类型,例如表单文件(DFM)和单位源文件(.PAS)。
Since it's quite common for Delphi applications to share code or previously customized forms, Delphi organizes applications into these project files. The project is made up of the visual interface along with the code that activates the interface.
由于Delphi应用程序共享代码或以前自定义的表单非常普遍,因此Delphi将应用程序组织到这些项目文件中。 该项目由可视界面以及激活该界面的代码组成。
Each project can have multiple forms that let you build applications that have multiple windows. The code that's needed for a form is stored in the DFM file, which can also contain general source code information that can be shared by all the application's forms.
每个项目可以具有多种形式,使您可以构建具有多个窗口的应用程序。 表单所需的代码存储在DFM文件中,该文件还可以包含可以由所有应用程序表单共享的常规源代码信息。
A Delphi project cannot be compiled unless a Windows Resource file (RES) is used, which holds the program's icon and version information. It might also contain other resources too, like images, tables, cursors, etc. RES files are generated automatically by Delphi.
除非使用Windows资源文件(RES)(该文件包含程序的图标和版本信息),否则无法编译Delphi项目。 它还可能包含其他资源,例如图像,表,光标等。RES文件由Delphi自动生成。
Note: Files that end in the DPR file extension are also Digital InterPlot files used by the Bentley Digital InterPlot program, but they have nothing to do with Delphi projects.
注意:以DPR文件扩展名结尾的文件也是Bentley Digital InterPlot程序使用的Digital InterPlot文件,但与Delphi项目无关。
DPR文件 ( DPR Files )
The DPR file contains directories for building an application. This is normally a set of simple routines which open the main form and any other forms that are set to be opened automatically. It then starts the program by calling the Initialize, CreateForm, and Run methods of the global Application object.
DPR文件包含用于构建应用程序的目录。 通常,这是一组简单的例程,这些例程会打开主窗体以及任何其他设置为自动打开的窗体。 然后,它通过调用全局Application对象的Initialize , CreateForm和Run方法来启动程序。
The global variable Application, of type TApplication, is in every Delphi Windows application. Application encapsulates your program as well as provides many functions that occur in the background of the software.
TApplication类型的全局变量Application在每个Delphi Windows应用程序中。 应用程序封装了您的程序,并提供了在软件后台发生的许多功能。
For example, Application handles how you would call a help file from the menu of your program.
例如,应用程序处理如何从程序菜单中调用帮助文件。
DPROJ is another file format for Delphi Project files, but instead, stores project settings in the XML format.
DPROJ是Delphi Project文件的另一种文件格式,但是以XML格式存储项目设置。
PAS文件 ( PAS Files )
The PAS file format is reserved for the Delphi Unit Source files. You can view the current project's source code through the Project > View Source menu.
PAS文件格式是为Delphi单位源文件保留的。 您可以通过“ 项目”>“查看源代码”菜单查看当前项目的源代码。
Although you can read and edit the project file like you would any source code, in most cases, you will let Delphi maintain the DPR file. The main reason to view the project file is to see the units and forms that make up the project, as well as to see which form is specified as the application's "main" form.
尽管您可以像读取任何源代码一样读取和编辑项目文件,但是在大多数情况下,您可以让Delphi维护DPR文件。 查看项目文件的主要原因是查看组成项目的单元和表格,以及查看将哪个表格指定为应用程序的“主”表格。
Another reason to work with the project file is when you're creating a DLL file rather than a standalone application. Or, if you need some startup code, such as a splash screen before the main form is created by Delphi.
使用项目文件的另一个原因是在创建DLL文件而不是独立应用程序时。 或者,如果您需要一些启动代码,例如在Delphi创建主表单之前启动屏幕 。
This is the default project file source code for a new application that has one form called "Form1:"
这是新应用程序的默认项目文件源代码,该应用程序具有一种称为“ Form1:”的形式。
program Project1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.RES}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1) ;
Application.Run;
end.
Below is an explanation of each of the PAS file's components:
以下是每个PAS文件组件的说明:
"program"
“ 程序 ”
This keyword identifies this unit as a program's main source unit. You can see that the unit name, "Project1," follows the program keyword. Delphi gives the project a default name until you save it as something different.
此关键字将该单元标识为程序的主要源单元。 您会看到在程序关键字后面跟随着单元名称“ Project1”。 在将项目另存为其他名称之前,Delphi会为项目提供默认名称。
When you run a project file from the IDE, Delphi uses the name of the Project file for the name of the EXE file that it creates. It reads the "uses" clause of the project file to determine which units are part of a project.
当您从IDE运行项目文件时,Delphi会将项目文件的名称用作它创建的EXE文件的名称。 它读取项目文件的“ uses”子句,以确定哪些单元是项目的一部分。
"{$R *.RES}"
“ {$ R * .RES} ”
The DPR file is linked to the PAS file with the compile directive {$R *.RES}. In this case, the asterisk represents the root of the PAS file name rather than "any file." This compiler directive tells Delphi to include this project's resource file, like its icon image.
DPR文件通过编译指令{$ R * .RES}链接到PAS文件。 在这种情况下,星号表示PAS文件名的根,而不是“任何文件”。 该编译器指令告诉Delphi包括该项目的资源文件,例如其图标图像。
"begin and end"
“ 开始和结束 ”
The "begin" and "end" block is the main source code block for the project.
“ begin”和“ end”块是项目的主要源代码块。
"Initialize"
“ 初始化 ”
Although "Initialize" is the first method called in the main source code, it isn't the first code that's executed in an application. The application first executes the "initialization" section of all the units used by the application.
尽管“ Initialize”是主要源代码中调用的第一个方法,但它不是在应用程序中执行的第一个代码。 应用程序首先执行“初始化” 应用程序使用的所有单位的“部分”。
"Application.CreateForm"
“ Application.CreateForm ”
The "Application.CreateForm" statement loads the form specified in its argument. Delphi adds an Application.CreateForm statement to the project file for each form that's included.
“ Application.CreateForm”语句加载在其参数中指定的表单。 Delphi将包含的每个表单的Application.CreateForm语句添加到项目文件中。
This code's job is to first allocate memory for the form. The statements are listed in the order that the forms are added to the project. This is the order that the forms will be created in memory at runtime.
该代码的工作是首先为表单分配内存。 这些语句按将表单添加到项目的顺序列出。 这是在运行时在内存中创建表单的顺序。
If you want to change this order, do not edit the project source code. Instead, use the Project > Options menu.
如果要更改此顺序,请不要编辑项目源代码。 而是使用“ 项目”>“选项”菜单。
"Application.Run"
“ Application.Run ”
The "Application.Run" statement starts the application. This instruction tells the pre-declared object called Application, to begin processing the events that occur during the run of a program.
“ Application.Run”语句启动应用程序。 该指令告诉预先声明的对象Application,开始处理程序运行期间发生的事件。
隐藏主窗体/任务栏按钮的示例 ( Example of Hiding the Main Form/Taskbar Button )
The Application object's "ShowMainForm" property determines whether or not a form will show at startup. The only condition for setting this property is that it has to be called before the "Application.Run" line.
Application对象的“ ShowMainForm”属性确定在启动时是否显示表单。 设置此属性的唯一条件是必须在“ Application.Run”行之前调用它。
//Presume: Form1 is the MAIN FORM
Application.CreateForm(TForm1, Form1) ;
Application.ShowMainForm := False;
Application.Run;
翻译自: https://www.thoughtco.com/understanding-delphi-project-files-dpr-1057652
delphi 捕获源