IntersectRect (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code example illustrates the usage of the IntersectRect function.

Code

uses
  System.SysUtils, System.Types;
var
  aRect1, aRect2, resultRect : TRect;
begin
  aRect1 := Rect(4,8,25,36);
  aRect2 := Rect(51,48,30,44);
  IntersectRect(resultRect,aRect1, aRect2);
  if (resultRect.Left = 0) and (resultRect.Top = 0) and (resultRect.Bottom = 0) and (resultRect.Right = 0) then
    WriteLn('The intersection of aRect1 and aRect2 returned false')
  else 
    WriteLn(resultRect.Left,' ',resultRect.Top,' ',resultRect.Right,' ', resultrect.Bottom);
//----------------------------------------------------------------------------------------------------------------
{ Other possible way to do it is by using the other overloaded function of IntersectRect: }
  if IntersectRect(aRect1, aRect2) then
    WriteLn('The two rectangles overlap!')
  else
    WriteLn('The two rectangles do not overlap!');
end.

Uses