Autor Beitrag
Battery
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Do 13.04.06 14:47 
Hallo
Ich möchte ein Programm schreiben. bei dem sehr viele Editfelder eingelesen werden sollen.
dazu habe ich bisher immer folgendes Fragment verwendet:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
case spielerzahl  of
1: spiel[1]:=edit1.Text;

2: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text; end;

3: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text; spiel[3]:=edit3.text; end;

4: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text; end;

5: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text; spiel[5]:=edit5.Text; end;

6: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text;
spiel[5]:=edit5.Text;spiel[6]:=edit6.Text; end;

7: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text; spiel[5]:=edit5.Text;
spiel[6]:=edit6.Text;spiel[7]:=edit7.Text; end;

8: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text; spiel[5]:=edit5.Text;
spiel[6]:=edit6.Text;spiel[7]:=edit7.Text; spiel[8]:=edit8.Text; end;

9: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;
spiel[3]:=edit3.text;spiel[4]:=edit4.text; spiel[5]:=edit5.Text;
spiel[6]:=edit6.Text;spiel[7]:=edit7.Text; spiel[8]:=edit8.Text;
spiel[9]:=edit9.Text; end;

10: begin spiel[1]:=edit1.Text; spiel[2]:=edit2.Text;spiel[3]:=edit3.text;
spiel[4]:=edit4.text; spiel[5]:=edit5.Text;spiel[6]:=edit6.Text;
spiel[7]:=edit7.Text;spiel[8]:=edit8.Text; spiel[9]:=edit9.Text;
spiel[10]:=edit10.Text; end;


Da dies sehr umständlich ist und viele mögliche Fehler beinhalteten kann, wollte ich fragen ob jemand eine kürzere Version, am besten über eine for-Schleife kennt.

Battery
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 13.04.06 14:53 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var i:integer;

for i := 1 to spielerzahl do
begin
  spiel[i]:=(FindComponent('edit'+inttostr(i)) as TEdit).text;
end;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Do 13.04.06 14:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
spiel[1]:=edit1.Text;
akt_wert:=2;
repeat
spiel[akt_wert]:=tedit(findcomponent('edit'+inttostr(akt_wert)).text;
inc(akt_wert);
until akt_wert>=spielerzahl;


ich denke so...(ungetestet)

//Edit: o_O nich richtig gelesen....na Marco´s Code is besser

_________________
GEIZ IST GEIL! - Ihr Sozialamt
Battery Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Sa 15.04.06 13:23 
Danke
HAt mir sehr geholfen! :D