DelphiBasics
Bounds
Function
Create a TRect value from top left and size values Classes unit
 function Bounds ( const Top, Left, Width, Height : Integer ) : TRect;
Description
The Bounds function creates a TRect rectangle value from Top, Left coordinates, and Width, Height size values.
 
It provides a useful alternative to the Rect function, where you must know the bottom and right coordinates rather than the rectangle size.
Related commands
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
TRect Holds rectangle coordinate 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 rectangles using Rect and Bounds
// 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
  Classes,   // Unit containing the Bounds command
  Types,
  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 using the Rect function
  // Note that we override the Types version of Rect.
  rectangle1 := Classes.Rect(Point(10, 60), Point(50, 80));

  // Set up an identical 2nd rectangle using the Bounds function
  rectangle2 := Bounds(10, 60, 40, 20);

  // 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 = 10,60,50,80
   Rectangle 2 coords = 10,60,50,80
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page