RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Classes.Rect Function

Creates a TRect structure from a set of coordinates.

Pascal
function Rect(ALeft: Integer; ATop: Integer; ARight: Integer; ABottom: Integer): TRect; overload;
function Rect(const ATopLeft: TPoint; const ABottomRight: TPoint): TRect; overload;
C++
TRect Rect(int ALeft, int ATop, int ARight, int ABottom);
TRect Rect(const TPoint ATopLeft, const TPoint ABottomRight);

Classes

Call Rect to create a TRect that represents the rectangle with the specified coordinates. Use Rect to construct parameters for functions that require TRect, rather than setting up local variables for each parameter.  

C++ Examples: 

 

/*
The following code displays the text "Hello, world!" in a
rectangle defined by the coordinates (10, 10) and (100, 100).
After displaying the text with the TextRect method, the code
draws a black, vertical line frame around the rectangle.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TRect TheRect = Rect(10,10,100,100);
  Canvas->TextRect(TheRect, 10, 10, "Hello World");
  Canvas->Brush->Color = clBlack;
  Canvas->FrameRect(TheRect);
}

 

Delphi Examples: 

{
The following code displays the text "Hello, world!" in a 
rectangle defined by the coordinates (10, 10) and (100, 100).
After displaying the text with the TextRect method, the code
draws a black, vertical line frame around the rectangle.
} 
procedure TForm1.Button1Click(Sender: TObject);
var TheRect: TRect;
begin
  TheRect := Rect(10,10,100,100);
  Form1.Canvas.TextRect(TheRect,10,10,'Hello, world!');
  Form1.Canvas.Brush.Color := clBlack;
  Form1.Canvas.FrameRect(TheRect);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!