What is the difference between a declared unit in the interface block and a declared unit in the implementation block?
1 Answers
If the unit is listed in the interface
section, it is available both in the interface section and the implementation section. However, if it is listed in the implementation
section, it is only available in that section.
Generally speaking, if you only need some unit for the implementation of a unit, then list it in the uses
clause of the imlementation section. That way it becomes clear what units the interface of your unit depends upon.
As you know, the interface section of a unit is what other units see. It is simply the 'interface' between your unit and other units. It is like a contract. "This is what I can do, and how you tell me to do it." The implementation section of the unit does all the work promised by the interface section. Here you simply 'implement' the unit; here you put the code of the classes/functions listed in the interface section. The contents of the implementation section is irrelevant details to other units.
This way you can divide your (huge) project into small parts, and it is easy to see how they work together, as a system.

- 105,602
- 8
- 282
- 384
-
6In addition: Units cannot link to each other in the interface section. UnitA cannot use UnitB in its interface section if UnitB uses UnitA in its interface as well. I actually prefer to ass uses in the interface section alone to prevent circular references. The compiler just won't allow it, and I'm sure that I do not get weird dependancies. – GolezTrol Apr 12 '12 at 14:37
-
@GolezTrol, sometimes you need circular references. That's why they are allowed in the implementation seccion. – Christopher Ramírez Apr 12 '12 at 15:33
-
Sometimes you may need them, most of the time you don't. I may choose to add a unit to the implementation section if I explicitly feel I need to. – GolezTrol Apr 12 '12 at 15:36