Create a TRect value from 2 points or 4 coordinates Classes unit
1  function Rect ( Left, Top, Right, Bottom : Integer ) : TRect;
2  function Rect ( TopLeft, BottomRight : TPoint ) : TRect;
The Rect function creates a TRect (rectangle) value from either 4 coordinates or 2 points.
When creating from two points TopLeft and BottomRight, you can pass two TPoint values, or use the Point function to generate them.

There are two Rect functions in the Classes and Types units. Only the former supports the second syntax.

If using both of these units in your code, and you specify Types after Classes you must prefix Rect with Classes to use this second syntax.
Related commands
Bounds Create a TRect value from top left and size values
Point Generates a TPoint value from X and Y values
PointsEqual Compares two TPoint values for equality
PtInRect Tests to see if a point lies within a rectangle
TPoint Holds X and Y integer values
TRect Holds rectangle coordinate values
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Create two rectangles using both syntaxes
  rectangle1, rectangle2 : TRect;

  // Set up the first rectangle using syntax 1
  rectangle1 := Rect(20, 40, 60, 80);

  // Set up the second rectangle using the Rect function
  rectangle2 := Classes.Rect(Point(20, 40), Point(60, 80));

  // Display the top left and bottom right coords of each rectangle
  ShowMessageFmt('Rectangle 1 coords = %d,%d,%d,%d',

  ShowMessageFmt('Rectangle 2 coords = %d,%d,%d,%d',
Show full unit code
   Rectangle 1 coords = 20,40,60,80
   Rectangle 2 coords = 20,40,60,80
Delphi Programming Neil Moffatt 2002 - 2018. All rights reserved.  |  Home Page