AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Verständnis bon Class TRect Definition

Verständnis bon Class TRect Definition

Ein Thema von bernhard_LA · begonnen am 20. Mär 2017 · letzter Beitrag vom 20. Mär 2017
Antwort Antwort
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.120 Beiträge
 
Delphi 11 Alexandria
 
#1

Verständnis bon Class TRect Definition

  Alt 20. Mär 2017, 08:14
wie steuere ich denn ob TRect nur durch 2 TPoints oder 4 Integer Werte aufgespannt wird ?



Delphi-Quellcode:
  TRect = record
  private
    function GetWidth: Integer;
    procedure SetWidth(const Value: Integer);
    function GetHeight: Integer;
    procedure SetHeight(const Value: Integer);
    function GetSize: TSize;
    procedure SetSize(const Value: TSize);
    function GetLocation: TPoint;
  public
    constructor Create(const Origin: TPoint); overload; // empty rect at given origin
    constructor Create(const Origin: TPoint; Width, Height: Integer); overload; // at TPoint of origin with width and height
    constructor Create(const Left, Top, Right, Bottom: Integer); overload; // at x, y with width and height
    constructor Create(const P1, P2: TPoint; Normalize: Boolean = False); overload; // with corners specified by p1 and p2
    constructor Create(const R: TRect; Normalize: Boolean = False); overload;
    class operator Equal(const Lhs, Rhs: TRect): Boolean;
    class operator NotEqual(const Lhs, Rhs: TRect): Boolean;
    class operator Add(const Lhs, Rhs: TRect): TRect;
    class operator Multiply(const Lhs, Rhs: TRect): TRect;
    class function Empty: TRect; inline; static;
    procedure NormalizeRect;
    function IsEmpty: Boolean;
    function Contains(const Pt: TPoint): Boolean; overload;
    function Contains(const R: TRect): Boolean; overload;
    function IntersectsWith(const R: TRect): Boolean;
    class function Intersect(const R1: TRect; const R2: TRect): TRect; overload; static;
    procedure Intersect(const R: TRect); overload;
    class function Union(const R1: TRect; const R2: TRect): TRect; overload; static;
    procedure Union(const R: TRect); overload;
    class function Union(const Points: Array of TPoint): TRect; overload; static;
    procedure Offset(const DX, DY: Integer); overload;
    procedure Offset(const Point: TPoint); overload;
...
...
 case Integer of
    0: (Left, Top, Right, Bottom: FixedInt);
    1: (TopLeft, BottomRight: TPoint);
  end;
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.896 Beiträge
 
Delphi 12 Athens
 
#2

AW: Verständnis bon Class TRect Definition

  Alt 20. Mär 2017, 08:33
Delphi-Quellcode:
constructor Create(const Left, Top, Right, Bottom: Integer); overload; // at x, y with width and height
constructor Create(const P1, P2: TPoint; Normalize: Boolean = False); overload; // with corners specified by p1 and p2
Macht das doch.

x = Left, y = Top, x+Width = Right, y+Height = Bottom

Rollo
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
10.993 Beiträge
 
Delphi 12 Athens
 
#3

AW: Verständnis bon Class TRect Definition

  Alt 20. Mär 2017, 08:46
wie steuere ich denn ob TRect nur durch 2 TPoints oder 4 Integer Werte aufgespannt wird ?
...
Delphi-Quellcode:
 case Integer of
    0: (Left, Top, Right, Bottom: FixedInt);
    1: (TopLeft, BottomRight: TPoint);
  end;

Die Darstellung ist im Speicherlayout identisch. Ein TPoint ist ja auch nichts anderes als zwei FixedInt-Werte für X und Y. Daher gilt
Delphi-Quellcode:
Left = TopLeft.X
Top = TopLeft.Y
Right = BottomRight.X
Bottom = BottomRight.Y
Es ist also völlig egal, über welches Create das TRect erzeugt wurde oder ob die Werte direkt zugewiesen wurden und wie es behandelt wird. Es kommt immer dasselbe raus.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz