Autor Beitrag
webmaker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Mi 23.07.03 14:01 
Hallo Leute,

wie kann ich alle Buttons, deren Name mit 'xyz_' (dann kommt ne Zahl) anfangen, freigeben? Wäre nett, wenn ihr mir helfen könntet.

Nachtrag: Mit FindComponent bekommen ich nicht die Anzahl der Buttons, die ich brauche um sie mit einer for-Schleife freizugeben. DA liegt eigentlich mein Problem.

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: Mi 23.07.03 14:15 
Da musst dum wohl die Liste aller Komponenten durchlaufen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  i: Integer;
begin
  for i := Application.ComponentCount - 1 downto 0 do
  begin
    if Copy(Application.Components[i].Name, 1, 4) = 'xyz_') then
      Application.Components[i].Free;
  end;
end;


Die Schleife zählt rückwärts, weil ich nicht genau weiß, ob nach dem Freigeben der Index der nachfolgenden Komponenten um eins verringert wird. So ist da egal.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mi 23.07.03 14:16 
Wenn die Buttons auf dem gleichen Form liegen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to ComponentCount-1 do 
  if (Components[i] is TButton) then 
    if copy((Components[i] as TButton).Name,1,4)='xyz_' then
      (Components[i] as TButton).Free;

Der Code ist nicht getestet

Moderiert von user profile iconTino: Absätze im Code eingefügt.

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mi 23.07.03 14:18 
@UC-Chewie: Mist du warst schneller und dein Code ist effektiver (Application.Components)...

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
webmaker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 205



BeitragVerfasst: Mi 23.07.03 14:30 
OK. Danke hatte es sogar fast genauso.

_________________
.::Wissen ist Macht, nichts wissen macht nichts::.