DelphiBasics
 TRectType 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
Author links

Buy Website Traffic at
Buywebsitetrafficexperts.com

Buy Proxies at
Buyproxies.io

Download this web site as a Windows program.

 Example code : Create one rectangle manually, another using Rect // Full Unit code.// -----------------------------------------------------------// You must store this code in a unit called Unit1 with a form// called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses  Types,   // Unit containing the TRect command  Classes,  Forms, Dialogs; type  TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  end; var  Form1: TForm1; implementation{\$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); 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; end. Hide full unit code Rectangle 1 coords = 0,0,40,60   Rectangle 2 coords = 20,40,60,80
 Delphi Programming © Neil Moffatt 2002 - 2018. All rights reserved.  |  Home Page