[Lazarus] Extending TRect breaks Lazarus

Anthony Walter sysrpl at gmail.com
Thu Nov 12 01:27:55 CET 2015


My solution is to define my own TRectI type which can implicitly convert
between TRectI <-> TRect. Also I use a TRectF which does the same thing,
but with floats as the dimenions ... MyRectInt := TRectI(MyRectFloat); ...
There is also TPointI and TPointF ...

{ TRectI }

  TRectI = record
  private
    function GetEmpty: Boolean;
    procedure SetTop(Value: Integer);
    procedure SetLeft(Value: Integer);
    function GetRight: Integer;
    procedure SetRight(Value: Integer);
    function GetBottom: Integer;
    procedure SetBottom(Value: Integer);
    function GetSize: TPointI;
    function GetTopLeft: TPointI;
    function GetBottomLeft: TPointI;
    function GetBottomRight: TPointI;
    function GetTopRight: TPointI;
    function GetMidPoint: TPointI;
  public
    X, Y, Width, Height: Integer;
    class operator Implicit(const Value: TRectI): TRect;
    class operator Implicit(const Value: TRect): TRectI;
    class operator Equal(const A, B: TRectI): Boolean;
    class operator NotEqual(const A, B: TRectI): Boolean;
    class function Create: TRectI; overload; static;
    class function Create(Size: TPointI): TRectI; overload; static;
    class function Create(W, H: Integer): TRectI; overload; static;
    class function Create(X, Y, W, H: Integer): TRectI; overload; static;
    function Equals(const Value: TRectI): Boolean;
    function Contains(X, Y: Integer): Boolean; overload;
    function Contains(const P: TPointI): Boolean; overload;
    procedure Center(X, Y: Integer); overload;
    procedure Center(const P: TPointI); overload;
    procedure Inflate(X, Y: Integer); overload;
    procedure Inflate(const P: TPointI); overload;
    procedure Offset(X, Y: Integer); overload;
    procedure Offset(const P: TPointI); overload;
    property Empty: Boolean read GetEmpty;
    property Left: Integer read X write SetLeft;
    property Top: Integer read Y write SetTop;
    property Right: Integer read GetRight write SetRight;
    property Bottom: Integer read GetBottom write SetBottom;
    property Size: TPointI read GetSize;
    property TopLeft: TPointI read GetTopLeft;
    property BottomLeft: TPointI read GetBottomLeft;
    property BottomRight: TPointI read GetBottomRight;
    property TopRight: TPointI read GetTopRight;
    property MidPoint: TPointI read GetMidPoint;
  end;
  PRectI = ^TRectI;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20151111/203ea0d3/attachment-0003.html>


More information about the Lazarus mailing list