![]() |
Delphi-Version: XE5
Zusammenhang TPicture und TGraphic
Liste der Anhänge anzeigen (Anzahl: 1)
Damit ich es endlich mal verstehe:
Delphi-Quellcode:
kann man als einen "Container" für ein
TPicture
Delphi-Quellcode:
sehen.
TGraphic
Delphi-Quellcode:
ist eine abstrakte Basisklasse für
TGraphic
Delphi-Quellcode:
,
TIcon
Delphi-Quellcode:
,
TMetaFile
Delphi-Quellcode:
und viele weitere...
TBitmap
Alles richtig soweit? Warum ergibt folgendes ein Speicherleck?
Delphi-Quellcode:
Ich verstehe das nicht- Die
procedure TForm2.FormCreate(Sender: TObject);
var myPic: TPicture; begin ReportMemoryLeaksOnShutdown := True; myPic := TPicture.Create(); myPic.Graphic := TBitmap.Create(); myPic.Free(); end;
Delphi-Quellcode:
-Property setzt
.Graphic
Delphi-Quellcode:
meines
FGraphic
Delphi-Quellcode:
auf das
TPicture
Delphi-Quellcode:
-Objekt und im Destruktor wird es wieder freigegeben.
TBitmap
|
AW: Zusammenhang TPicture und TGraphic
Die Zuweisung
Delphi-Quellcode:
veranlasst, dass der Inhalt der Bitmap-Instanz in die Graphic-Instanz kopiert (per
TPicture.Graphic := TBitmap.Create;
Delphi-Quellcode:
) wird.
Assign
Die Bitmap-Instanz wird also nicht übernommen, von dir nicht freigegeben und dümpelt so bis zum Ende im Speicher rum -> Leck (Ein Blick in den Setter-QuellCode hätte dir das auch verraten ;)) EDIT: Gerade gesehen, selbst die Dokumentation ist da eindeutig ![]() Zitat:
|
AW: Zusammenhang TPicture und TGraphic
Wenn man TPicture.Graphic einen Wert zuweist, wird intern (im Setter) eine neue Instanz erzeugt und deren Werte mit Assign aus dem Original kopiert. Somit sind beide Instanzen völlig unabhängig voneinander. Das bedeutet aber auch, dass Du für die Freigabe Deiner Bitmap selbst zu sorgen hast.
|
AW: Zusammenhang TPicture und TGraphic
Hoppla, stimmt.
Delphi-Quellcode:
NewGraphic sagt eigentlich schon alles... :oops:
procedure TPicture.SetGraphic(Value: TGraphic);
var NewGraphic: TGraphic; begin NewGraphic := nil; if Value <> nil then begin NewGraphic := TGraphicClass(Value.ClassType).Create; NewGraphic.Assign(Value); NewGraphic.OnChange := Changed; NewGraphic.OnProgress := Progress; end; try FGraphic.Free; FGraphic := NewGraphic; Changed(Self); except NewGraphic.Free; raise; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:22 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