Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 15.01.10 11:02 
Hi, Delpher,

mal eine Anfängerfrage: :oops: :oops: :oops:

(Wie) kann man den folgenden Code kürzen?

ausblenden Delphi-Quelltext
1:
2:
3:
  writeln(t1, edit1.text); writeln(t1, edit2.text); writeln(t1, edit3.text);
  writeln(t1, edit4.text); writeln(t1, edit5.text); writeln(t1, edit6.text);
  writeln(t1, edit7.text); writeln(t1, edit8.text);


Danke, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Fr 15.01.10 11:13 
ausblenden Delphi-Quelltext
1:
2:
for i:=1 to 8 do
    wrtieln(t1,   (Form1.FindComponent('edit'+IntToStr(i)) AS TEdit).text       );

_________________
Delphi: XE - OS: Windows 7 Professional x64


Zuletzt bearbeitet von Horschdware am Fr 15.01.10 11:14, insgesamt 3-mal bearbeitet
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Fr 15.01.10 11:13 
entweder so:
ausblenden Delphi-Quelltext
1:
2:
  writeln(t1, edit1.text + #13#10 + edit2.text + #13#10 + edit3.text + #13#10 + edit4.text + #13#10 +
              edit5.text + #13#10 + edit6.text + #13#10 + edit7.text + #13#10 + edit8.text);

oder so:
ausblenden Delphi-Quelltext
1:
2:
  for i:=1 to 8 do
    writeln(t1, TEdit(FindComponent('edit'+IntToStr(i))).text);

gibt noch viele andere möglichkeiten ^^
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 15.01.10 11:30 
Vielen Dank, ihr zwei!
Gruß, Detlef :D :D

_________________
ut vires desint, tamen est laudanda voluntas
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Fr 15.01.10 13:07 
Man kann die Edits auch zur Laufzeit erzeugen und dann direkt in ein Array packen.

Wenn ich die Edits zur Entwurfszeit erzeuge, wie du hier, dann weise ich sie manchmal auch einem Array zu (OnCreate)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  Edits: array[1..10of TEdit;

..

Edits[1] := edit1;
Edits[2] := edit2;
..



Vorteil: ist recht übersichtlich, man hat nur einmal Arbeit (und das vor allem mit Copy & Paste) und kann dann sein eigenes Array benutzen. FindComponent geht aber natürlich auch.

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 17.01.10 20:50 
Danke, Tilman, sehr interessant!
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas