Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - Alle untergeordneten childs-Elemente finden


Daniel L. - Do 07.10.10 12:05
Titel: Alle untergeordneten childs-Elemente finden
Hallo

ich versuche, alle childs einer Komponente, und auch deren childs usw. aufzuzeigen.

Beispiel: auf einer Form liegt Panel1.
Auf Panel1 liegen Panel2 und Button1.
Auf Panel2 liegt Button2.
Nun sollen alle child-Elemente von Panel1 und deren childs gezeigt werden.

Ich probiere das rukursiv mit controls, erhalte aber eine Fehlerlmeldung:



Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure  TForm1.GetControls (Contrl : TWinControl);
var i : integer;
    co : TWinControl;
begin
for i := 0 to  contrl.ControlCount  - 1 do
   begin
     co := contrl.Controls  [i]; --> Fehler:"Inkompatible Typen: 'TWinControl' und 'TControl'"
     showmessage (contrl.Name);
     GetControls (co);
   end;
end;


Danke für Hilfe: Daniel Lutz


bummi - Do 07.10.10 12:18


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure  TForm1.GetControls (Contrl : TWinControl);
var i : integer;
    co : TWinControl;
begin
for i := 0 to  contrl.ControlCount  - 1 do
   begin
     if  contrl.Controls[i] is TWinControl then
        begin
         co := TWinControl(contrl.Controls[i]);
         showmessage (co.Name);
         GetControls (co);
        end;
   end;
end;


aber Du suchst wahrscheinlich

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure  TForm1.GetParent (Contrl: TWinControl);
begin
  if Assigned(Contrl.Parent) then
    begin
    Showmessage(Contrl.Parent.Name);
    GetParent(Contrl.Parent);
    end;

end;


Daniel L. - Do 07.10.10 12:38

sorry, ich suche nach den Child-Komponenten und nicht nach den Parents.
Hab ich oben editert.

Daniel