Question

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?

Was it helpful?

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.

OTHER TIPS

If you're to call Rect in a tight loop (which doesn't do I/O or similar), consider calling types.Rect, which is what classes.Rect really does; it calls types.Rect (but then you may need to inline your own Rect...). Otherwise it doesn't matter, I wouldn't bother including 'types' in 'uses' just to save one level of indirection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top