Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Neue Font in ein von abgeleitetes Object einfügen.


Tweafis - So 29.06.03 15:32
Titel: Neue Font in ein von abgeleitetes Object einfügen.
Ich wollte mein TPanelEx um eine Font erweitern die bei der Überschrift benutzt wird (nicht die normale Font...) Ich hab das jetzt so probiert:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
private
  FCaptionFont: TFont;
  procedure SetCaptionFont(const Value: TFont);
  {...}
published
  property CaptionFont: TFont read FCaptionFont write SetCaptionFont;

{...}

// in Create:
  inherited Create(AOwner);
  FCaptionFont := TFont.Create;
  FCaptionFont.Size := 12;
  FCaptionFont.Color := clBlack;

// in Destroy
  FCaptionFont.Free;
  inherited Destroy;

{ ... }
procedure TPanelEx.SetCaptionFont(const Value: TFont);
begin
  FCaptionFont.Assign(Value);
end;


Ich bekomme aber eine Zugriffsverlezung (EAccessViolation) an Adresse xyz.... Was ist da falsch?

//Edit:
Komischerweise aber nur beim Lesen Oo; Wenn ich nicht auslese sondern nur in Create schreibe passiert nichts... Parent gibts ja nicht... Außerdem wüsste ich gern was ich nehmen soll in Create:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
constructor TPanelEx.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCaptionFont := TFont.Create;
  FCaptionFont.Size := 12;
  FCaptionFont.Color := clBlack;
end;


or


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
constructor TPanelEx.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  CaptionFont := TFont.Create;
  CaptionFont.Size := 12;
  CaptionFont.Color := clBlack;
end;


Tweafis - So 29.06.03 16:57

Weiß jetzt woran es lag:

Ich hab Create nicht overriden, es wurde nicht aufgerufen und die Font wurde nicht erstellt.
Habs durch die zwei Warnings gemerkt (Create verbirgt die Basismethode...)