Detailed explanation of Delphi unit files:
1. Library unit file header: which declares the name of the library unit.
2.Interface part:
It starts with the reserved word interface and ends with the reserved word implementation, which is used to declare referenced units, constants, data types, variables, procedures and functions. The variables, constants, data types, procedures and functions declared in the Interface part can be used externally. References are common to the entire program. That is, these declarations are visible and accessible to all units that reference this unit.
In the Interface part, you only need to write the headers of the procedures and functions. The specific definitions are given in the implementation part below.
The Interface part can be divided into multiple optional parts, namely the unit introduction part (uses), the constant description part, the type description part, the variable description part, and the procedure and function declaration part.
3.Implementation part:
The Implementation part is divided into two parts. One part is the declaration part, including the declaration of unit references, constants, types, variables, procedures and functions, which is similar to the Interface part.
There are two differences:
(1): What is declared in the Implementation section is public and visible only to this unit. Even if other units reference this unit, they cannot access them.
(2): The procedures and functions declared in the Implementation part do not need to follow the rule of declaration first and then definition, but the definitions of the procedures and functions can be written directly. The other part is the definition of the procedures and functions declared in the Interface part.
4.Initialization part:
Used to initialize the library unit, the code here is executed first. If multiple library units contain Initialization parts, their execution order is consistent with the order of appearance of the referenced units in the uses part of Program.
5.Finalization part:
Usually used to release resources allocated in the Initialization part. If multiple library units contain the Finalization part, the execution order is exactly the opposite to the Initialization part.