SmartPascal
TRect
Type
Holds rectangle coordinate values Types unit
  type
    TRect = packed record
    case Integer of
      0: (Left, Top, Right, Bottom: Integer);
      1: (TopLeft, BottomRight: TPoint);
  end;
Description
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
 
Example code : Create one rectangle manually, another using Rect
var
  rectangle1, rectangle2 : TRect;

begin
  // 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',
                 [rectangle1.Left,
                  rectangle1.Top,
                  rectangle1.Right,
                  rectangle1.Bottom]);

  ShowMessageFmt('Rectangle 2 coords = %d,%d,%d,%d',
                 [rectangle2.Left,
                  rectangle2.Top,
                  rectangle2.Right,
                  rectangle2.Bottom]);
end;
Show full unit code
   Rectangle 1 coords = 0,0,40,60
   Rectangle 2 coords = 20,40,60,80