Autor Beitrag
DelphiNoob
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Sa 02.04.05 11:49 
Hi,

ich verwalte per TList meine dynamisch erstellten Komponenten.
Für jeden Typ, eine List (TPanel, TBevel, TLabel, etc).

Soweit so gut. Das Problem ist die Löschung.

Ich verwende momentan folgenden Code der aber nicht funktioniert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  if (LabelList.Count > 0) then //Wenn einträge existieren
    for i:=0 to LabelList.Count-1 do begin //geh in eine Schleife
      TLabel(LabelList.Items[i]).free //Free Komponente Item[i]
    end;


Zum testen habe ich vor und nachher mir den Count mal per MessageDlg
ausgeben lassen. Leider keine Reaktion.

Ich weiß momentan nicht wirklich wieso es nicht funktioniert. Ich hoffe
daher auf einen kurzen Vorschlag hier im Forum. Besten Dank.

Mfg
DelphiNoob
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 12:04 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  with LabelList do
    if Count > 0 then
    begin
      for I := 0 to Count - 1 do
        TLabel(Items[I]).Free;
      Clear;
    end;


Items aus TList werden nur gelöscht, wenn du Delete oder Clear benutzt. Sollte dir dieses Verhalten nicht gefallen, dann musst du TObjectList benutzen.

_________________
Ciao, Sprint.
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Sa 02.04.05 12:11 
Problem gelöst, wieder was gelernt.

Danke