Holds rectangle coordinate values Types unit
    TRect = packed record
    case Integer of
      0: (Left, Top, Right, Bottom: Integer);
      1: (TopLeft, BottomRight: TPoint);
The TRect type is a record holding rectangle values as either 4 coordinates or 2 points.
This is a classic example of the use of the Case part of a record.
When creating from two points TopLeft and BottomRight, you can pass two TPoint values, or use the Point function to generate them.
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
Rect Create a TRect value from 2 points or 4 coordinates
TPoint Holds X and Y integer values
 Author links

 Download this web site as a Windows program.

Example code : Create one rectangle manually, another using Rect
  rectangle1, rectangle2 : TRect;

  // Set up the first rectangle manually
  rectangle1.Left   := 0;
  rectangle1.Top    := 0;
  rectangle1.Right  := 40;
  rectangle1.Bottom := 60;

  // Set up the second rectangle using the Rect function
  rectangle2 := 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 = 0,0,40,60
   Rectangle 2 coords = 20,40,60,80
Delphi Programming Neil Moffatt 2002 - 2020. All rights reserved.  |  Home Page