![]() |
Property TFont in neuer Kompo klappt nicht
Wie kann ich in ner neuen Kompo ne Eingenschaft vom Typ TFont hinzufügen. Im grunde das gleiche wie die Eigenschaft "Font" beim Button oder nem Label. Bei mir klappt das nicht.
Immer wenn ich im OI bei meiner Kompo die Font ändern will kommt das: Zitat:
Delphi-Quellcode:
type TCSTyp = (tAdresse, tRechnung, tLieferung);
TCSAdressLabel = class(TCSQRRichText) private FUeberschriftFont:TFont; public constructor Create(AOwner:TComponent);override; destructor Destroy;override; published property UeberschriftFont : TFont read FUeberschriftFont Write FUeberschriftFont; end; |
Re: Property TFont in neuer Kompo klappt nicht
Wenn Du das direkte Beschreiben einer Exemplarvariablen zulässt, ist die Referenz auf das zuvor erzeugte Exemplar verloren. Darüber hinaus ist nicht klar, wo das zugewisene Exemplar letztlich wann freigegeben wird:
Delphi-Quellcode:
Verwende stattdessen eine transparente Zuweisung der Form
myFont:= TFont.Create;
try AnObject.Font:= myFont; AnotherObject.Font:= myFont; finally FreeAndNil(myFont); end;
Delphi-Quellcode:
wobei Du das Exemplar hinter FFont einmalig im Konstruktor erzeugst, bzw im Destruktor zerstörst.
TMyClass = class
private FFont: TFont; procedure SetFont(const AValue: TFont); public property Font: TFont read FFont write SetFont; //... procedure TMyClass.SetFont(const AValue: TFont); begin FFont.Assign(AValue); end; |
Re: Property TFont in neuer Kompo klappt nicht
Zitat:
|
Re: Property TFont in neuer Kompo klappt nicht
Irgendwo muss FFont mit einem Objekt "belegt" werden. Das sollte, wie bei Objekten, die aus anderen Objekten zusammengesetzt (aggregiert) sind, innerhalb des Konstruktors geschehe. zB so:
Delphi-Quellcode:
Das Exemplar sollte dann spätestens im Destruktor wieder freigegeben werden
constructor TMyClass.Create;
begin inherited; FFont:= TFont.Create; //.. some more initialization code end;
Delphi-Quellcode:
destructor TMyClass.Destroy;
begin FreeAndNil(FFont); inherited; end; |
Re: Property TFont in neuer Kompo klappt nicht
AHHH. Vielen Dank. Ich wollt erst das AValue anstatt FFont im Constructor erstellen :wall: Klappte natürlich nicht
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:52 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