Autor Beitrag
DelphiBeginner
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Mo 06.12.04 18:34 
Hi,

ich habe folgendes Problem ich habe ein Panel: Panel1. Auf diesem Panel werden durch eine Funktion bei einem ButtonClick neue Labels erstellt.
Gibt es nun eine Möglichkeit alle Labels zu zerstören? Brauche das Panel wieder im Anfangszustand, d.h Panel ohne irgendwelche Labels.



Gruß Der Delphibeginner
Loki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 34

Win XP Home

BeitragVerfasst: Mo 06.12.04 18:44 
Ich weis jetzt nicht ob es eine schnellere einfachere Lösung gibt aber ich würde es so machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i := 0 to Form1.ComponentCount - 1 do
begin
  if Form1.Components[i] is TLabel then
    if TLabel(Form1.Components[i]).Parent is TPanel then
      TLabel(Form1.Components[i]).Free;
end;


Hab es nicht getestet, aber ich denke es geht so :D
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Mo 06.12.04 20:34 
Habe jetzt auch nur kurz drüber geschaut.
Aber wenn der Code funktioniert, dann nur in der Weise, dass alle Labels auf welchem Panel auch immer weggeknallt werden.

Vielleicht sollte doch noch irgendwie auf das eine Panel abgeprüft werden? :wink:
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 06.12.04 20:38 
Das sollte gehen, ist aber ungestestet
ausblenden Delphi-Quelltext
1:
2:
[...]
if TLabel(Form1.Components[i]).Parent = Panel1 [...]

_________________
We are, we were and will not be.
Loki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 34

Win XP Home

BeitragVerfasst: Mo 06.12.04 20:39 
Hmm ja stimmt habe ich vergessen. Also dann wäre es wohl so besser:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  i := 0;
  while i < Form1.ComponentCount do
  begin
    if Form1.Components[i] is TLabel then
      if TLabel(Form1.Components[i]).Parent is TPanel then
        if TPanel(TLabel(Form1.Components[i]).Parent).Name = 'Panel1' then
        begin
          TLabel(Form1.Components[i]).Free;
          i := i - 1;
        end;
      i := i + 1;
  end;


Teste das ganze jetzt mal eben. Falls ich noch einen Fehler entdecke ändere ich es.

/EDIT: So hab es getestet so funktioniert es. Ist aber nicht auf Sonderfälle geprüft !!!