Autor Beitrag
Nerzhul
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 15.04.04 13:51 
Hallo,

Irgendwie steh ich grad auf dem Schlauch. Und zwar möchte ich Komponenten dynamisch auswählen ... z.B. habe ich 3 Labels [Label1, Label2, Label3] und würde gerne in etwa sowas machen können:

ausblenden Delphi-Quelltext
1:
for i:=1 to 3 do (Label + IntToStr(i)).Caption := 'test';					


Funktioniert natürlich so nicht. Wie muss ich vorgehen?

Danke schonmal,

-M

Moderiert von user profile iconUdontknow: Code-Tag gesetzt.


Zuletzt bearbeitet von Nerzhul am Do 15.04.04 13:54, insgesamt 1-mal bearbeitet
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 15.04.04 13:53 
Hallo! :welcome:

Das Stichwort lautet "FindComponent".

ausblenden Delphi-Quelltext
1:
for i:=1 to 3 do TLabel(Form1.FindComponent('Label' + IntToStr(i))).Caption := 'test';					


Cu,
Udontknow


Zuletzt bearbeitet von Udontknow am Do 15.04.04 13:59, insgesamt 2-mal bearbeitet
HawkLUED
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62

WinXP
Delphi 7 Enterprise, Delphi 2007
BeitragVerfasst: Do 15.04.04 13:56 
Titel: Hi!
Hi,

denke, da könnten die Stichworte: ComponentCount und ControlCount nützlich sein!!

Wenn die Label auf einem Formular liegen, kannst Du alle Komponenten und Controls auf diesem Formular mit einer Schleife durchlaufen!!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
for i := 0 to Form1.ComponentCount-1 do
begin
   if Form1.Component[i] is TLabel then
  begin
     (Form1.Component[i] as TLabel).Caption := 'Label Nr.' + i;
  end;
end;

_________________
Wenn Debuggen der Vorgang ist, Fehler aus einem Programm auszubauen,
dann ist Programmieren der Vorgang, Fehler in ein Programm einzubauen !
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 15.04.04 13:58 
@HawkLued:

Was, wenn er noch andere Labels auf dem Formular hat, die er nicht umbenennen möchte? Besser also FindComponent (s.o.).

Cu,
Udontknow
Nerzhul Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 15.04.04 14:07 
Oh Mann, danke :) Genau das wars.

Nur fürs Protokoll:

(FindComponent('Label' + IntToStr(i)) as TLabel).Caption := 'test';

-M