![]() |
Re: vom Objekt zur Komponente
Zitat:
|
Re: vom Objekt zur Komponente
also der Type-Teil ist in der gleichen Unit und die Variable ist dann in der Klasse
muss es in die Klasse ; |
Re: vom Objekt zur Komponente
Das würde sich sehr anbieten.
|
Re: vom Objekt zur Komponente
dann müsste ich eine Klasse TObject in der Klasse TComponent definieren.
geht das? |
Re: vom Objekt zur Komponente
Ich redete von der Variablen Dreieck und nicht der Klasse TVieleck
|
Re: vom Objekt zur Komponente
OK, hab ich jetzt falsch verstanden.
Die Variable Vieleck ist in der Kalsse, das schon |
Re: vom Objekt zur Komponente
Zeig mal die komplette Unit.
|
Re: vom Objekt zur Komponente
Hier mal ein Teil
Delphi-Quellcode:
unit C_Ball_V2;
{- [ITNERFACE]-Teil -----------------------------------------------------------} interface uses Windows, Classes, Graphics ; function PointEllipse(Mittelpunkt : TPoint ; Winkel, ARadius : integer; BRadius : integer = 0) : TPoint ; function PointBezier(A, B, C, D : TPoint; Teilung, Schritt : Integer) : TPoint ; type {- Typendefinierung -----------------------------------------------------------} TSite = (lsLeft, lsRight) ; TPaintStyle = (psLine, psColored) ; {- TVieleck -------------------------------------------------------------------} TVieleck = class // [PRIVATE]-Teil private Mittelpunkt : TPoint ; FVieleck : array of TPoint ; Canvas : TCanvas ; // [PUBLIC]-Teil public constructor Create(AMittelpunkt : TPoint; ACanvas : TCanvas) ; procedure Paint(AColor : TColor) ; end ; {- TBall ---------------------------------------------------------------------} TBall = class(TComponent) // [PRIVATE]-Teil private FMittelpunkt : TPoint ; FCanvas : TCanvas ; Dreieck : TVieleck; FPaintStyle : TPaintStyle ; FbgColor : TColor ; FLineColor : TColor ; // [PUBLIC]-Teil public constructor Create(AOwner : TComponent) ; overload; override; // Standard-Construktor constructor Create(AOwner : TComponent; AMittelpunkt : TPoint; ACanvas : TCanvas) ; overload; procedure Paint ; procedure Clear ; procedure Repaint ; // [POTECTED]-Teil protected // [PUBLISHED]-Teil published property Canvas : TCanvas read FCanvas write FCanvas ; property XMittelpunkt : Integer read FMittelpunkt.x write FMittelpunkt.x ; property YMittelpunkt : Integer read FMittelpunkt.y write FMittelpunkt.y ; property PaintStyle : TPaintstyle read FPaintStyle write ChangePaintStyle ; property bgColor : TColor read FbgColor ; property LineColor : TColor read FLineColor ; end ; procedure Register; {- [IMPLEMENTATION]-Teil ------------------------------------------------------} implementation procedure Register; begin RegisterComponents('Ball', [TBall]); end; {- TVieleck -------------------------------------------------------------------} // Generiert TVieleck auf ACanvas mit AMittelpunkt constructor TVieleck.Create(AMittelpunkt : TPoint; ACanvas : TCanvas) ; begin inherited Create; Canvas := ACanvas ; Mittelpunkt := AMittelpunkt ; end ; // Erstellt TVieleck aus den Daten procedure TVieleck.Paint(AColor : TColor) ; begin Canvas.Pen.Width := 2 ; Canvas.Pen.Color := AColor ; Canvas.Polyline(FDreieck) ; end ; {- TBall ----------------------------------------------------------------------} // Standard-Constructor constructor TBall.Create(AOwner : TComponent) ; begin inherited Create(AOwner); // geerbter Konstruktor FCanvas := nil ; // Zur Sicherheit FMittelpunkt.x := -1 ; // Zur Sicherheit FMittelpunkt.y := -1 ; // Zur Sicherheit Dreieck := TVieleck.Create(FMittelpunkt, FCanvas) ; end ; constructor TBall.Create(AOwner : TComponent; AMittelpunkt : TPoint; ACanvas : TCanvas) ; begin Create(AOwner) ; // Standartwerte für Propertys FbgColor := clWhite ; FLineColor := clBlack ; FLungColor := $008B82FF ; FCanvas := ACanvas ; FMittelpunkt := AMittelpunkt ; end ; // Zeichent procedure TBall.Paint ; begin Dreieck.Paint(FLineColor) ; end ; // Löschte procedure TBall.Clear ; begin Dreieck.Paint(FbgColor) ; end ; // Zeichnet neu procedure TBall.Repaint ; begin // Löschen Clear ; // Neuzeichnen Paint ; end ; |
Re: vom Objekt zur Komponente
Erst mal fällt auf, dass deine Bezeichnungen inkonsistent sind.
Suffix F für alle privaten Felder, Suffix A für Parameter, T für Typen Aber da FDreieck von den Werten, anderer Felder abhängt, war der 2. Konstruktor doch richtig. |
Re: vom Objekt zur Komponente
ok abgesehen, dass meine Bezeichnungen inkonsistent sind weiß ich wo der Fehler liegt.
Zu dem Zeitpunkt wenn der Constructor ausgeführt wird ist das Canvas noch nil und auf ein nicht existierendes Canvas kann man nicht zeichnen. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:10 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz