Autor Beitrag
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 12:03 
Moin... ;)

Ich möchte per FindComponent alle Komponenten eines gewissen Typs finden. Sonst muss man ja immer als Parameter den Namen der Komponenten angeben.

Danke schonmal. ;)
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 12:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure FindComponentByType(Owner: TComponent; const ClassName: String; Result: TList);
var
  I: Integer;
begin

  Result.Clear;

  for I := 0 to Owner.ComponentCount - 1 do
    if Owner.Components[I].ClassNameIs(ClassName) then
      Result.Add(Owner.Components[I]);

end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  List: TList;
begin

  List := TList.Create;
  FindComponentByType(Self, 'TImage', List);
  // ...
  List.Free;

end;

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 12:20 
Danke!! :D Werd's sogleich ausprobieren!! ;)
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 12:45 
Jop. Funktioniert genauso, wie ich wollte. Danke, danke!! :flehan:

Mit FindCmponent geht's halt nicht. Werd nächstes Mal auch nach anderem gucken. ;)
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:01 
Hmm.. Was ist der Owner bzw. Parent von allen Forms? :gruebel:

Wenn ich mir die anzeigen lassen will mit
ausblenden Delphi-Quelltext
1:
2:
ShowMessage(Form1.Parent.Name);
ShowMessage(Form1.Owner.Name);

dann bekomm ich beim ersten eine Access-Violation und beim zweiten bekomm ich nix zurück. :shock:
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 13:10 
In deinem Fall ist der Owner von Form1 TApplication. Da musst du ClassName benutzen.

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:12 
Also, wenn wir grad mal deinen Code von da oben nehmen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  List: TList;
begin

  List := TList.Create;
  FindComponentByType(TApplication, 'TImage', List);
  // ...
  List.Free;

end;

:gruebel:
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 13:18 
Statt TApplication musst du Application nehmen. Das wird aber mit TImage nicht funktionieren. In der Regel findest du bei Application nur TForm's.

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:19 
Genau die will ich auch suchen. ;)
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:22 
Hmm... So hatte ich's aber... Und so geht's nicht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure Blublabb;
var
i: Integer;
begin
for i := 0 to Application.ComponentCount - 1 do
if Application.Components[i].ClassNameIs('TForm'then begin
ShowMessage('0');
end;
end;

Er bringt kein einziges Mal die ShowMessage. :(
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 13:24 
Das Problem ist ja, das der Klassenname deiner Form z.B. TForm1 ist. Also müsstest du da mit "is TForm" prüfen.
Schreib doch lieber mal, was du ganz genau vor hast. Dann kann man da besser drauf eingehen.

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:27 
Ich brauch einfach alle Forms, weil ich auf jedem Formular zur Laufzeit ein TImage erstellen will. ;)
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 13:31 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin

  for I := 0 to Application.ComponentCount - 1 do
    if Application.Components[I] is TForm then
      ShowMessage(Application.Components[I].Name);

end;


Funktioniert auf jeden Fall bei TForm's die von Delphi erstellt worden sind. Bei dynamisch-erstellten Form's ist es abhängig wie du sie erstellt hast.

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:37 
Hätte ich auch selber draufkommen können. :autsch:
Bin halt grad ziemlich beschäftigt mit GFS-Dokumentation. ;)

Jetzt bekomm' ich weiter hinten im Code bei
ausblenden Delphi-Quelltext
1:
BkgrndImage.Parent := Application.Components[i];					

jedoch diese Meldung da:
ausblenden Quelltext
1:
[Error] Unit1.pas(79): Incompatible types: 'TWinControl' and 'TComponent'					

Wenn ich allerdings statt Application.Components[i]; einfach Form1 schreib' (und ich teste ja im Moment auch nur mit Form1) dann geht es. :gruebel: Form1 ist doch TForm und somit auch TComponent oder? Fehlt da nur eine Eigenschaft? :gruebel:
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 02.04.05 13:42 
user profile iconWeBsPaCe hat folgendes geschrieben:
ausblenden Quelltext
1:
[Error] Unit1.pas(79): Incompatible types: 'TWinControl' and 'TComponent'					

Wenn ich allerdings statt Application.Components[i]; einfach Form1 schreib' (und ich teste ja im Moment auch nur mit Form1) dann geht es.

Da musst du typecasten.

ausblenden Delphi-Quelltext
1:
BkgrndImage.Parent := TForm(Application.Components[XXX]);					

_________________
Ciao, Sprint.
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 02.04.05 13:51 
Ok. Vielen, vielen, vielen Danke!! :flehan: :flehan: ;)

Das "Gesammtergebnis" ist hier zu "bewundern". :lol:

Danke!!