Delphi XE5 tutorial 2: Program Organization

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Content from Delphi XE5 UPDATE 2 "Delphi Reference" official help, my level is limited, welcome expert correction of errors´╝ü

Also welcome to Delphi learning materials to finished, are interested in can QQ:

1 Program Organization

1        Program organization

Delphi programs are usually divided into source-code modules called units. Most programs begin with a program heading, which specifies a name for the program. The program heading is followed by an optional uses clause, then a block of declarations and statements. The uses clause lists units that are linked into the program; these units, which can be shared by different programs, often have uses clauses of their own.

The application program is often divided into a plurality of source code modules, we call them unit (unit). Most applications in the program header (program), which specifies a name for the program. In the program after the head is an optionaluses Clause, and is composed of a statement and command statement block(block). uses Clause lists those linked to the program unit, the unit can be shared with different programs, and usually have their ownuses Clause.

The uses clause provides the compiler with information about dependencies among modules. Because this information is stored in the modules themselves, most Delphi language programs do not require makefiles, header files, or preprocessor "include" directives.

uses Clause to the compiler provides all the dependencies between modules of information, because this information is stored in the module itself, therefore, Object Pascal program does not need to makefile files, header files and the include preprocessor directives.

1.1  Delphi Source Files

1.1  DelphiThe source file

The compiler expects to find Delphi source code in files of three kinds:

The compiler expects to obtain Pascal source code in the following three types of documents:

Unit of the source file (file extension .pas)

The project file (file extension .dpr)

Package source file (file extension .dpk)

Unit source files typically 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 program file in traditional Pascal, organizes the unit files into an application. Embarcadero development tools automatically maintain a project file for each application.

The main part of the source file contains code, each program contains a project file and a plurality of unit file. The project file is equivalent to a traditional Pascal language of the ‘ ’ program files, which put the unit file organization into a program. Embarcadero development tools automatically for each program maintains a project file.

If you are compiling a program from the command line, you can put all your source code into unit (.pas) files. If you use the IDE to build your application, it will produce a project (.dpr) file.

If you compile a program from the command line, you can put all the source code in a unit file(.pas)In, but if you use IDE to create the program, you must have a project file(.dpr).

Package source files are similar to project files, but they are used to construct special dynamically linkable libraries called packages.

Package source files are similar to the project file, but they used to create bundles called special dynamic link library(DLL).

1.2 Other Files Used to Build Applications

1.2Other documents required to create the program

In addition to source-code modules, Embarcadero products use several non-Pascal files to build applications. These files are maintained automatically by the IDE, and include

In addition to the source code files, Embarcadero tools also need several non Pascal files to create program. These files are automatically maintained by IDE, including the following documents:

Form file (Win32 platform extension .dfm)

A resource file, (extension .res )(compiled resource file)

Project options file, (extension .dof )

A VCL form file contains the description of the properties of the form and the components it owns. Each form file represents a single form, which usually corresponds to a window or dialog box in an application. The IDE allows you to view and edit form files as text, and to save form files as either text (a format very suitable for version control) or binary. Although the default behavior is to save form files as text, they are usually not edited manually; it is more common to use Embarcadero's visual design tools for this purpose. Each project has at least one form, and each form has an associated unit (.pas) file that, by default, has the same name as the form file.

A VCL form file contains the form property and it contains the description of the components. Each form file represents a form, usually corresponds to the procedure in a window or dialog box. IDE allows viewing and editing form files as text, and can save it as text or binary format. Although the default is to save the form to a text, but usually do not manually edit it, the more common form of visual design tools provided by the use of Embarcadero. Each project has at least one form, each form has an associated unit file(.pas), By default, the unit file name and form the same filename.

In addition to VCL form files, each project uses a resource (.res) file to hold the application's icon and other resources such as strings. By default, this file has the same name as the project (.dpr) file.

In addition to the VCL form document, a resource file to use each project(.res)Save the bitmap as the program icon. By default, the files and project files(.dpr)The same name.

A project options (.dof) file contains compiler and linker settings, search path information, version information, and so forth. Each project has an associated project options file with the same name as the project (.dpr) file. Usually, the options in this file are set from Project Options dialog.

Project options file(.dof)Contains settings, search path and version information the compiler and linker etc.. Each project corresponds to an option file, it and the project file name. Typically, file option is accomplished through the Project Options dialog.

Various tools in the IDE store data in files of other types. Desktop settings (.dsk) files contain information about the arrangement of windows and other configuration options; desktop settings can be project-specific or environment-wide. These files have no direct effect on compilation.

Many tools in the IDE is stored in other types of files. Desktop settings file(.dsk)Contains the window arrangement information and other setting items. Desktop settings or specific to a project (and a related engineering), or to the whole environment (environment-wide) (not specific to a project, to all works are effective). These files have no effect on Compilation.

1.3 Compiler-Generated Files

1.3The compiler generates the file

The first time you build an application or a package, the compiler produces a compiled unit file (.dcu on Win32) for each new unit used in your project; all the .dcu files in your project are then linked to create a single executable or shared package. The first time you build a package, the compiler produces a file for each new unit contained in the package, and then creates both a .dcp and a package file. If you use the GD compiler switch, the linker generates a map file and a .drc file; the .drc file, which contains string resources, can be compiled into a resource file.

In the first generation of a program or a package, each new unit used in compiler for the project to create a compiler (had) unit file (in Windows for.dcu). In all engineering.dcu The file is linked to a single executable or shared packet; when the first generation of a package, each new unit compiler contains for the package to create a.dcu The file, and then create.dcp File and Bao Wenjian. If the use of–GD Switch, the linker to generate a map file and.drc File, .drcThe file contains the string resource, can be compiled into a resource file.

When you build a project, individual units are not recompiled unless their source (.pas) files have changed since the last compilation, their .dcu/.dpu files cannot be found, you explicitly tell the compiler to reprocess them, or the interface of the unit depends on another unit which has been changed. In fact, it is not necessary for a unit's source file to be present at all, as long as the compiler can find the compiled unit file and that unit has no dependencies on other units that have changed.

When you create a project, unless since the last compiled unit file(.pas)Changed, or not found and.dcu/.dpu File, or explicitly tell the compiler to compile it, another unit or unit interface dependent has changed. In fact, there is no need for a unit source files to compile all the unit file. As long as the compiler can find (the) compiled unit file, and the unit and the other unit has been changed without the dependency.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Quinn at February 16, 2014 - 3:23 PM