ITWales.com
Section 2: .DPR, .DFM, .DCU, .PAS, .DPG, .OPT, .CFG, HELP!
Now that we have seen how simple it is to create a basic Windows application, we will look at what we just did in a little bit more
detail. Firstly, we will look at the way in which Delphi stored the information we just created.
When you start programming in Delphi, the IDE will, by default create a "project file" for the application. The project file is the
equivalent of the main body in an ordinary Pascal program. It contains the entry point for the program, and is responsible for storing a
list of the locations of all of the units that the program comprises. A unit is nothing more than a file that holds a self contained
block of code. Therefore a unit might contain one particular object, or the code to support one dialog box or form. Although there is
always one unit for every form or dialog in the project, the reverse is not true (i.e. there may be units that do jobs other than
containing the code for a specific form or dialog). There is only ever
one
project file in an application, and it has the file extension ".DPR" (short for Delphi project). If you decide to save your project
file as "MY_APPLICATION.DPR", then when compiled, you will end up with an executable with the filename "MY_APPLICATION.EXE".
In any one project, it is
very
likely that you will have
many
unit files. One unit per dialog box or form, plus some additional units for application specific objects and miscellaneous code is
typical. These "units" of code are given the extension .PAS when they are saved from the IDE. When Delphi compiles a project to create an
executable, it first compiles the units, and creates a compiled image of each in a separate file. These files are given the extension
.DCU, (short for Delphi compiled unit). These files by definition contain binary data, and cannot be edited with a text editor. Once all
of the code has successfully been compiled, these .DCU files are "linked" to create the executable. The linking process is automatic, and
so fast that you will probably not notice it happening until you start writing really large programs.
Each form or dialog box that you generate, must be stored in a way that allows the IDE to recreate it exactly as you originally
designed it. The IDE needs to be able to do this for editing, and also to build it into the executable so that it can be correctly
displayed at run-time. The information about the forms is stored in files with the extension .DFM (short for Delphi form). These files
contain binary data, and hence the only simple way to look at them is to use the Delphi visual interface development environment. Delphi
will allow you to view a form file in a text format, but it is rarely necessary or desirable to do so.
In large projects, it is occasionally the case that you will find yourself compiling more than one program, potentially with some
shared units. Under these conditions, it is possible within Delphi to specify a program group, and to get Delphi to recompile
automatically any programs in the group that are affected by a change to one of the shared units. The list of .DPR files that make up the
group of related programs is saved to the disk with the extension .DPG (Short for Delphi program group)
Delphi provides the programmer with an enormous number of settings for the environment and for the compiler itself (what level of
optimisation to apply etc.) These settings are stored in a binary format in the .OPT and .CFG files. It is best to ignore these, and
avoid deleting them, as your carefully chosen settings will return to the defaults if you do so.
In order to provide some level of safety, the Delphi environment automatically creates backup version of all of the .PAS and .DFM
files when you start to edit them. These are created in the same directory as the original file, and are given the same file name with
the same extension, except with the first letter of the extension changed to a "~" character (and the remaining characters shifted one to
the right). For example, if your project contains a file MainForm.pas, when you edit it, Delphi will create a backup file MainForm.~pa.
Likewise form1.dfm will become form1.~df
All of this means that a large Delphi project can end up containing literally hundreds of files, and it is essential therefore to be
careful you store each new project in a new sub-directory to avoid overwriting and losing files.
Figure 9 A Medium Scale Delphi Project
Home, Services, Events, Features, Interviews, Profiles, Reviews, News, Resources, Press