Autor Beitrag
Wombat23
Hält's aus hier
Beiträge: 7



BeitragVerfasst: So 04.01.04 16:48 
Hi Leute,
sitze gerade über meinem zweiten größeren Programm. Ich habe ein Formular, in dem 20 Edits (Edit1..Edit20) vorhanden sind, deren Text ich im Programmablauf bei allen gleichzeitig auf '0,00' setzen möchte.
Gibt es dafür eine elegantere Methode als 'edit1 :=0',00' bis edit10:= '0,00' per Hand einzugeben, z.B. per Schleife ? Ich krieg den Komponentennamen nicht in eine Variable rein :(
Danke schonmal !
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 04.01.04 16:51 
Hallo!

Da arbeitest Du am besten mit "FindComponent". Geht dann z.B. so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
VAR i : Integer;
    myComponent : TComponent;
begin
  for i:=1 TO 20 DO
  begin
    myComponent := FindComponent('edit'+IntToStr(i));
    
    if myComponent is TEdit then
      TEdit(myComponent).Text := '0,00';
  end;
end;


MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 04.01.04 16:53 
Gruß,

1. Und hier die kürzere Variante
ausblenden Delphi-Quelltext
1:
2:
for i := 1 to 20 do 
TEdit(FindComponent('Edit'+inttostr(i))).text := '0,00';

2. :welcome: im DF
3. Versuchs nächstes Mal bitte erstmal mit der Suchfunktion

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 04.01.04 16:55 
@GSE:
Schon klar, dass es auch so geht, aber ich wollte noch die "Sicherheitsabfrage" drin haben.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Wombat23 Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: So 04.01.04 16:55 
Danke für die schnelle Antwort !