Autor Beitrag
G-S
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Sa 09.08.08 15:02 
Hallöchen wieder,

meine Frage ist: wie entferne ich Bilder? Bei der SuFu hab ich gefunden das man einfach das Image auf Nil setzen soll, also:
TImage := Nil;
Aber würde dann nicht das Bild dennoch im Speicher liegen bleiben? Oder wie es ein Bekannter von mir nennt: "Zombie".
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 09.08.08 15:43 
Das kommt drauf an, wenn es ein normales von dir erstelltes Objekt ist, dann kannst du Objektvariable.Free oder FreeAndNil(Objektvariable) benutzen.

Wenn du, wie es hier aussieht, ein TImage unsichtbar machen willst, dann solltest du lieber mit Visible arbeiten und es nach Bedarf anzeigen und vestecken, es sei denn du brauchst es danach wirklich nicht mehr.
G-S Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Sa 09.08.08 15:46 
Nein, ich brauche es danach nicht mehr und es befindet sich in einem TImage.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 09.08.08 15:55 
Ich meinte ob du das TImage selbst noch benötigst, nicht das Bild darin.

In diesem speziellen Fall kannst tatsächlich Image1.Picture.Bitmap := nil schreiben, da in dem entsprechenden Setter überprüft wird, ob der übergebene Wert nil ist, das alte Bild wird aber auf jeden Fall freigegeben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TPicture.SetGraphic(Value: TGraphic);
var
  NewGraphic: TGraphic;
begin
  NewGraphic := nil;
  if Value <> nil then
  begin
//...
  end;
  try
    FGraphic.Free;
    FGraphic := NewGraphic;
//...
end;
Das funktioniert aber nur, weil bei der Zuweisung der Eigenschaft Bitmap die Methode SetBitmap aufgerufen wird, die wiederum SetGraphic aufruft und dann sich darum kümmert. Bei einer normalen Variablen ist das etwas anderes.
G-S Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Sa 09.08.08 16:32 
Ja, das TImage wird noch benötigt.

Also räumt sich dieses Bild selbst aus dem Speicher weg, richtig?
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 09.08.08 17:56 
user profile iconG-S hat folgendes geschrieben:
Also räumt sich dieses Bild selbst aus dem Speicher weg, richtig?

Jop. Wie jaenicke schon gesagt hat, wird die alte Bitmap beim Zuweisen der Property 'Bitmap' eines TImage in jedem Fall freigegeben.

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
G-S Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Sa 09.08.08 18:33 
Danke für die schnelle Hilfe.

Dann kann hier von mir aus zu gemacht werden. =)
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 09.08.08 18:43 
Ein Threat wird geschlossen, wenn eine vernünftige Diskussion nichtmehr möglich ist ;)

Ob die Frage beantwortet ist, interessiert dabei nicht :) Vielleicht hat ja noch jemand Bemerkungen oder ein ähnliches Problem(wobei dann im allgemeinen kein Uralter Threat wieder ausgegaben werden sollte).

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)