Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#6

Re: Kann Klasse von Record erben?

  Alt 16. Dez 2009, 17:22
Zitat von MisterNiceGuy:
Ich will eine TRect-Klasse haben weil ich diese, falls sie nicht gefüllt ist auf = nil überprüfen kann, bzw ihr einen weiteren Parameter verpassen kann der sagt ob sie initialisiert ist oder nicht.

Leider ist das mit dem "kopieren" aus dem Record nicht so leicht. Folgendes bringt eine Fehlermeldung "end erwarter aber case gefunden"

Delphi-Quellcode:
type TjfRect = class
  case Integer of
    0: (Left, Top, Right, Bottom: Integer);
    1: (TopLeft, BottomRight: TPoint);
end;
Kein Problem wenn man ein bisschen überlegt

Delphi-Quellcode:
TjfRect = class
private
  FLeft, FTop, FRight, FBottom: Integer;
public
  property Left: Integer read FLeft write FLeft;
  property Top: Integer read FTop write FTop;
  property Right: Integer read FRight write FRight;
  property Bottom: Integer read FBottom write FBottom;
 
  property TopLeft: TPoint read GetTopLeft write SetTopLeft;
  property BottomRight: TPoint read GetBottomRight write SetBottomRight;
end;

function TjfRect.GetBottomRight: TPoint;
begin
  Result := Point(FRight,FBottom);
end;

function TjfRect.GetTopLeft: TPoint;
begin
  Result := Point(FLeft,FTop);
end;

procedure TjfRect.SetBottomRight(const Value: TPoint);
begin
  FRight := Value.X;
  FBottom := Value.Y;
end;

procedure TjfRect.SetTopLeft(const Value: TPoint);
begin
  FLeft := Value.X;
  FTop := Value.Y;
end;
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat