Autor Beitrag
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Mi 04.06.03 12:44 
Hi, Ich hab ein Problem mit FindComponent bzw eine Frage:

Ich habe eine Form mit 1 Button (Button1) 3 Labels (Label1-3) + einem button (Label4).

Jetzt möchte ich jeweils die Caption ändern.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var x: integer;
    compon: TComponent;
begin
  for x:=1 to 3 do begin
    compon := FindComponent('Label'+IntToStr(x));
    (compon as TLabel).Caption := 'Bla'+IntToStr(x);
    (compon as TButton).Caption := 'Bla'+IntToStr(x);
  end;
end;


So funktioniert es nicht, ohne die zeile (compon as TButton)... geht es, jedoch wird der button nicht geändert. Jetzt meine frage:

Kann man irgendwie überprüfen welchem typ compon angehört (z.B. if compon = TButton then ...)?[/delphi]

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 04.06.03 13:52 
Ich glaube so sollte es gehen:
ausblenden Delphi-Quelltext
1:
If Compon is TLabel Then					


Gruß
Tino
Tweafis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Mi 04.06.03 16:58 
Tino hat folgendes geschrieben:
Ich glaube so sollte es gehen:
ausblenden Delphi-Quelltext
1:
If Compon is TLabel Then					


Gruß
Tino


THX, ich wusste doch dass es da irgendeinen operator gibt.

Fis

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.