Program structure
Each program begins with a heading, which specifies the name of the program, followed by an optional uses clause and a block of declarations and statements. Object Pascal programs are typically divided into modules of source code called units. The optional uses clause contains the list of units that are used by the program. These units, in turn, may use other units specified in their own uses clauses.
Every Object Pascal program uses the built-in System unit. This unit contains predefined constants, types, functions, and procedures, such as basic functions to write and read from the command line or work with files. If you explicitly place the System in the uses clause, you will get an error message that this unit is already used and that it is not legal to use a unit multiple times in one unit. Apart from the System unit, Delphi comes with many units that are not used automatically. They must be included in the uses clause. For example, the System.SysUtils unit is typically used in every Delphi project because it provides some basic functionality, such as the declaration of an exception class needed for structured exception handling. Unit names may contain dots, such as in the case of System.SysUtils. Only the last part is the actual unit name, and all the preceding identifiers constitute a namespace that is used to logically group units. In some cases, it is possible to skip the namespace part, and the compiler will still be able to compile a unit. The order of the units listed in the uses clause is important and determines the order in which they will be initialized.
The first time you compile an app or a package (a special type of project custom components and editors used by the IDE), the compiler produces a compiled unit file (.dcu on Windows) for each unit used in the project. These files are then linked to create an executable file. In the Project menu, or in the Project Manager context menu, there are options to either Compile or Build the current project. When you compile your project, individual units are not recompiled, unless they have been changed since the previous compilation or their compiled units cannot be found. If you choose Build, all the compiled units are regenerated. In fact, the compiler just needs the compiled unit to generate the executable, so it might not have access to the source code of a unit at all. With pre-compiled units, you can build even very big projects very quickly.