What are the benefits of adding a usage proposal for a unit in an implementation section?

If I put a block in the uses section of the unit implementation section, identifiers declared in such a block are not available for the interface section.

What is the advantage of this and the inability to use identifiers from the mentioned device in the interface?

Is there any practical advantage (for example, eliminating undesirable side effects) if you want to add used units to the implementation section instead of a simple section section?

+6
source share
2 answers

The biggest problem is that using the interface in a section can lead to circular dependencies and compilation failure. If block A uses block B in the interface section, then block B cannot use block A in its interface section.

So, you often have to make at least some uses in the implementation section.

Otherwise, I personally prefer to use units of use in the interface section, if at all possible. The main reason is scope and hiding. If there is a collision with the definition of names (two blocks define the same name, and the second use hides the first), then the same name was in scope throughout the block.

+5
source

Adding one to the uses clause of the implementation section allows this device to be a private dependency only with implementation , not with interface . If UnitA uses UnitB, but no one except UnitA cares whether UnitA uses UnitB because UnitA does not use UnitB, then why advertise the dependency and prevent the interface ? In addition, if you ever need to remove UnitB and / or replace it with something else, declaring it in the uses clause of the implementation section avoids changing the interface , which will affect any device that uses UnitA.

+13
source

Source: https://habr.com/ru/post/950916/


All Articles