- 2.2.10.1 -
TMT Pascal Language Description
Pascal Language Structure
Programs and UnitsUnits
Units can be compiled separately and take the following form:
unit Unitname;
interface
[Declaration]
implementation
[Declaration]
[
begin
[statement [; statement]]
]
[
end // required to close the initialization section
postlude
begin
[statement [; statement]]
]
end.
Unitname is the name of the unit. This is the same name that you will
use in programs to reference the unit. There are three sections within each
unit.
Interface Section
The interface section contains declarations of types, constants,
variables, procedures, and functions that are public and accessible to
other programs and units. When declaring procedures and functions in the
Interface section, only the procedure header is required.
These declarations are similar to using the forward clause that
tells TMT Pascal that the complete declaration is further ahead in the
program. The entire procedure declaration is done in the implementation
section. Local variables and procedures that need not be accessible outside
of the unit may be declared in the implementation section.
Implementation Section
The implementation section contains local types, constants,
variables, labels, procedures and functions.
Procedures and functions are local to the unit unless their header is also
declared in the interface section. The implementation section
contains complete procedure and function declarations.
Initialization Section
The initialization section starts immediately after the begin statement.
This code block is executed by the main program that uses the unit. It is
executed prior to the main code block.
Postlude Section
The postlude section is optional, and it begins with the reserved word
postlude and continues until the end of the unit. It contains
statements that are executed when the main program terminates.
You should use the finalization section to free resources that were
allocated in the initialization section.
Each unit is terminated by the end statement followed by a dot.
The reserved words interface and implementation must be
specified in a unit. The initialization and postlude
sections are optional.
In Borland Pascal, private procedures are compiled as near while public
procedures are far. Therefore private procedures are more efficient.
In TMT Pascal both private and public procedures are near and equally
efficient.
|
|
|
Programs and Units |
Table of Content |
Programs |
- 2.2.10.1 -