Search code examples
delphidelphi-xe2rect

Delphi XE2: Rect ambiguity?


The Rect function is declared in two units:

System.Classes.Rect
System.Types.Rect

Why this ambiguity? Is one of these functions deprecated? Which one should be preferred?


Solution

  • From the documentation, System.Types.Rect takes integer values for the four corners of the rectangle; System.Classes.Rect on the other hand also provides an overload that takes two TPoints - one for top-left, one for bottom right. Both return a TRect so it's really a matter of choice which you use.

    The latter is more flexible (offering two overloads) so it's probably best to make sure you include Classes after Types in your uses clause (if using both) to not hide the more versatile method provided by Classes.