Section 5: Compiling, Building, Linking, Running
You have probably already realised that you have done this. But there are a couple of points that are worth making explicitly.
Delphi, like Turbo Pascal before it, is very good at disguising the complexity of the compilation process. I am old enough to
remember using command line tools that required the use of a separate compiler and linker (and I'm sure some of you do as well). Delphi
masks all of that, taking in to account the date stamp of all of the files involved in the project, checking the date of the compiled DCU
files against the date stamp on the .PAS files, deciding what dependencies exist between the different files, and re-compiling the
minimum amount of code necessary.
You can more or less totally rely on Delphi to get this right every time, and need rarely perform a "build" instead of a compile.
(Performing a Build ensures that Delphi re-compiles everything, regardless of whether it seems necessary or not). There are only 4
occasions
when this will be necessary...
1) If you have changed a global compiler directive (Delphi does not detect this)
2) If you want to know how many lines of code your project contains
3) If you have transferred files from another machine where the date/time stamping of the files may cause Delphi to mis-calculate which
files need re-compiling.
4) If you really don't trust my assurances about the compiler!
There are quite a number of ways to compile your program. The quickest way is to press F9. This will cause the compiler to re-compile the
program and then to run it immediately in the built in debugging environment.
If you want to compile only, without running the code, then pressing Ctrl F9 will do this for you. Alternatively if you aren't very good
at remembering key stroke combinations, then you should selected Project from the main menu, followed by Compile. By default, Delphi does
not show you your progress (a strange choice for a default in my opinion), but turning the option on is simple enough:
Figure 10 Turning on Compilation Progress Monitoring
Select the tools menu - and then the "Environment options" sub-option. On the resulting dialog box, select the preferences tab, and tick
the "Show Compiler Progress" option.
Figure 11 Delphi's Progress Dialog, Showing 2 Errors
If Delphi finds an error in your program (and sooner or later, you can be sure it will!), it will continue to compile until it can
compile no more. Gone are the days when compilers would only produce the first error
message then bail out. This is both good and bad. Clearly, once an error message has been found the compiler will attempt to recover,
and to do so must make an assumption about what you really meant... The end result is often a stream of error messages, the
correction of one of which gets rid of the majority of the rest.
Delphi can also generate hints and warnings. These are an invaluable addition to a compiler. Hints provide optimisations like pointing
out places where you have declared variables which are then never used.
Whereas the warnings indicate probable sources of error. For example if you write a line like:
A := A + 3;
BEFORE you h
ave assigned a value to A, then the compiler will warn you that this is the case. If you have an "if then else" statement in a function
that fails to include all possible cases, and there is a danger that the value returned might be undefined as a result...
then once again the compiler comes to the rescue. In short, the compiler really holds the programmer's hand, and we should all be
heavily in favour of that!
Figure 12 Delphi Showing Hints and Warnings
Building a project is simply a case of selecting a different menu option (there is no keyboard shortcut for "build"). Select Project, and
then Build to force Delphi to recompile all of the units in your program.
Menu: Home, Services, Events, Features, Interviews, Profiles, Reviews, News, Resources, Press