Search code examples
delphidelphi-7

Why are functions like "Point" / "Rect" / "Bounds" (etc) declared both in Classes and in Types unit?


I have noticed that in Delphi 7 functions like Point / Rect / Bounds (etc) are declared and implemented both in Classes and in system Types unit.

Is there a reason for that? is it also true for newer Delphi versions?

(My guess is that one could use Types unit to avoid the Classes overhead when needed)


Solution

  • In older versions these types and functions were declared in Classes. As the RTL was developed, especially to support cross-platform, it became desirable for the these types to be available to units that did not include Classes.

    The Types unit was introduced to enable that. The Types unit has no uses dependencies so can safely be used by any other unit, no matter how low level.

    The master declarations were moved to Types, and Classes re-exports these types and functions for the benefit of existing code that imports from Classes. So for instance, SysUtils uses Types, but is not permitted to use Classes. Moving these types and functions to a dependency free unit like Types enables that.

    This change was made between Delphi 5 and Delphi 6, which was the start of the Delphi cross-platform developments. In that instance it was Kylix, but the restructuring of the RTL benefited the future cross-platform developments, even though Kylix was abandoned.