What is the difference between the types defined in the implementation compared to the device interface section?

Almost all of the Delphi code I read has all the class type definitions in the module interface section, but I have seen the random use of type definitions in the implementation section.

What is the difference between the two and why should I use this?

+6
delphi
source share
3 answers

It is quite simple: the types defined in the implementation are visible only in the implementation, so they cannot be used as argument types or return values ​​in the interface. So, post your type definitions (like everything else ;-) based on whether these types are just implementation details or something you want to make visible from the outside, that is, through the interface!

+12
source share

Scope. Interface declarations are publicly available and available to other units if that unit is included in the Uses offer. Implementations of the declaration are private and are available only within this specific unit.

+5
source share

There is a general difference between code changes in an interface and the implementation of code changes at compile time. If you add a class or modify an existing class in an interface section, then all units that reference the changed block must be recompiled. However, a change in the implementation section (a new subclass or code change) will require recompilation of this device, and the IDE will bundle the previously compiled DCU plus a new one together to create an EXE file.

In general, the main advantage is that it allows you to develop code to hide implementation details - define the parent class in the interface and any subclasses in the implementation. Or define classes in the implementation if they are needed solely to implement the class / method behavior available in the interface section.

+3
source share

All Articles