![]() |
Problem mit Property
Hallo Leute ich hab volgenden Quellcode:
Delphi-Quellcode:
Wenn ich jetzt im OI auf die property Font zugreifen will erscheint jedes mal die Fehlermeldung
unit Ball;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TMyPoint = class(TPersistent) Private fx, fy : integer ; Published constructor Create ; property x: integer read fx write fx; property y: integer read fy write fy; end; TBall= class(TComponent) private FMittelpunkt : TPoint ; BMittelpunkt : TMyPoint ; FImage : TImage ; FFont : TFont ; { Private-Deklarationen } protected { Protected-Deklarationen } public constructor Create(AOwner : TComponent) ; destructor Destroy ; procedure GetPoint(Y : integer) ; { Public-Deklarationen } published property MittelpunktLeft : integer read FMittelpunkt.x write FMittelpunkt.x ; property MittelpunktHight : integer read FMittelpunkt.y write FMittelpunkt.y ; property Mittelpunkt : TMyPoint read BMittelpunkt write BMittelpunkt ; property PaintPlane : TImage read FImage write FImage ; property Font: TFont read FFont write FFont; { Published-Deklarationen } end; procedure Register; implementation constructor TMyPoint.Create ; begin fy := 0 ; fx := 0 ; end ; procedure Register; begin RegisterComponents('Kugel', [TBall]); end; constructor TBall.Create(AOwner: TComponent); begin inherited Create(AOwner) ; BMittelpunkt := TMyPoint.Create ; FMittelpunkt.y := 0 ; PaintPlane := nil ; FFont := TFont.Create; end; destructor TBall.Destroy ; begin BMittelpunkt.Free ; FFont.Free ; inherited Destroy ; end ; procedure TBall.GetPoint(Y : integer) ; begin FMittelpunkt.y := Y ; end ; end. Zitat:
Sebastian |
Re: Problem mit Property
Für ein Property das ein Objekt darstellt brauchst du eine Setter-Methode.
Delphi-Quellcode:
procedure TBall.SetFont(AFont: TFont);
begin FFont.Assign(AFont); end; |
Re: Problem mit Property
ich hab die Set-Procedure jetzt wie folgt eingebaut
Delphi-Quellcode:
es erscheint dennoch der gleiche Fehler.
property Font: TFont read FFont write SetFont;
procedure TBall.SetFont(AFont : TFont) ; begin FFont.Assign(AFont) ; end ; Was mache ich falsch |
Re: Problem mit Property
Ich schätze mal du musst im constructor erst mal eine Instanz von TFont erzeugen FFont := TFont.Create;
Im destructor dann natürlich wieder entfernen. |
Re: Problem mit Property
muss ich deine Schätzung leider wiederlegen, denn wenn du den Quelltext angesehen hast müsstest du gesehen haben das ich das gemscht habe, wenn ich es falsch gemacht habe dann ok.
Ich weiß einfach nicht warum das so nicht funktioniert :-( |
Re: Problem mit Property
Kann mir hier niemand weiterhelfen?
|
Re: Problem mit Property
Poste doch mal den kompletten Code, falls er nicht zu umfangreich ist.
|
Re: Problem mit Property
Zitat:
|
Re: Problem mit Property
Ist momentan noch nicht mehr Code wie oben zu sehen, ich versuch im Moment aus einem Objekt eine Komponente zu basteln und hab mich jetzt mal an die Propertys gewagt, aber geht nicht.
|
DP-Maintenance
Dieses Thema wurde von "Matze" von "Programmieren allgemein" nach "Object-Pascal / Delphi-Language" verschoben.
Delphi-Frage |
Re: Problem mit Property
Naja, TMyPoint, TBall, TLunge... ich steig da nicht ganz durch :gruebel:
|
Re: Problem mit Property
Naja das TLunge gehört da nicht hin. Also muss TBall heißen, hab ich auch schon geändert.
Was wollte ich eigentlich machen, ich will eine Property haben die einen Punkt mit x und y Koordinate bereitstellt, hier also TMyPoint oder wenn es geht auch TPoint. Das mit der TFont hab ich nur ausprobiert, da ich dachte das müsste doch gehen, aber ging so auch nicht. Meine Frage wäre nun wie muss ich die Prpoerty mit ihren proceduren schrieben das es geht. Ein Beispiel wäre ganz hilfreich da ich auf dem Gebiet noch nicht sehr viel gearbeite habe. Sebastian |
Re: Problem mit Property
Zitat:
|
Re: Problem mit Property
ok ihr sagt der SourceCode der Oben steht ist korrekt, warum kommt dann immer dieser dähmliche Fehler?
Mal ganz allgemein kann mir jemand ein funktionierendes Beispiel Posten, wie ich z.B. einen Punkt (TPoint) als property initialisiere? Ich komm einfach nicht darauf was falsch ist und offenbar gibt es auch keinen Fehler :-( ??? |
Re: Problem mit Property
Hey sebi87,
ich hab halt einfach nur geguckt in den Sourcecode von TCustomControl, wie das da mit FFont gemacht wird. Ganz genauso. Mehr als moralische Unterstützung für dich kann ich hier leider nicht liefern. :cry: |
Re: Problem mit Property
Da bin ich ja beruhigt das wenigsten mein Ansatz richtig war, genau da hab ich auch geschaut, aber irgendwie geht es dennoch nicht, trotzedem danke für die unterstützung
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:14 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 by Thomas Breitkreuz