PtInRect (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code example returns whether a given TPoint belongs to the area of a TRect. This is done with the help of PtInRect function.

Code

...
uses
  System.SysUtils, System.Types;

var
  aPoint: TPoint;
  aRect: TRect;

begin
    aRect := Rect(1,2,8,10);
    aPoint.X := 3;
    aPoint.Y := 4;

    if PtInRect(aRect,aPoint) then
      writeln('The point appears to be within the bounds of the TRect.')
    else 
      writeln('The point does not belong to the TRect area.');
    { The PtInRect routine returns a Boolean value. In this particular case, the point can be found between the bounds of the TRect object. }
    { We can also use TRect's method - Contains}
    if aRect.Contains(aPoint) then
      writeln('The point appears to be within the bounds of the TRect.')
    else 
      writeln('The point does not belong to the TRect area.');
end.

Uses