Autor Beitrag
luis_figo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 25.08.05 10:40 
Tag Leute!
Habe folgendes Problem, Wunsch:

Möchte folgende Anweisung wie folgt verstricken:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Gewicht[1]:=StrToFloat(Form1.Gewicht1.Text);
Gewicht[2]:=StrToFloat(Form1.Gewicht2.Text);
Gewicht[3]:=StrToFloat(Form1.Gewicht3.Text);
usw......


Ist es möglich statt jedes Gewicht einzeln zu ändern einen Array daraus zu machen!?
Wenn ja - wie!
Danke!

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 25.08.05 12:03 
Moin und :welcome: im Forum!

Einfachste Lösung wie folgt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  GewichtEdit: Array[1..3] of TEdit;
  i: Integer;

begin
  GewichtEdit[1] := Form1.Gewicht1;
  GewichtEdit[2] := Form1.Gewicht2;
  GewichtEdit[3] := Form1.Gewicht3;
[...]
  for i := 1 to 3 do
    Gewicht[i] := StrToFloat(GewichtEdit[i].Text);

cu
Narses
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 25.08.05 12:08 
Hallo und auch von mir ein :welcome:

Ich denke, dass dir das Stichwort Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT weiterhelfen dürfte. Da macht zwar aus deinen einzelnen Kompos keine Arrays, aber du kannst die komponenten dadurch in einer Schleife ansprechen.

_________________
We are, we were and will not be.
luis_figo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 25.08.05 13:14 
user profile iconNarses hat folgendes geschrieben:
Moin und :welcome: im Forum!

Einfachste Lösung wie folgt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  GewichtEdit: Array[1..3] of TEdit;
  i: Integer;

begin
  GewichtEdit[1] := Form1.Gewicht1;
  [b]GewichtEdit[2] := Form1.Gewicht2;
  GewichtEdit[3] := Form1.Gewicht3;
[...][/b]
  for i := 1 to 3 do
    Gewicht[i] := StrToFloat(GewichtEdit[i].Text);

cu
Narses


Nicht ganz denn ich will mir ja diese eintipperei ersparen!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 25.08.05 13:22 
Hallo,
FINDCOMPONENT ist die eine Möglichkeit und
Form.Components[] könnte eventuell auch etwas für Dich sein.
Es wird die Tageigenschaft der Edits ausgewertet,
nur die mit einem Tag <> 0 werden berücksichtigt,
der Tag-Wert wird dann mit dem Index des Array "verstrickt".
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
//...
var MyArr : Array [1..10] of Integer;
//...
Edit1.Tag := 1;
Edit1.Tag := 2;
Edit1.Tag := 3;
//...
procedure TForm1.LiesEdits;
    z : Integer;
    aObj : TObject;
begin
  for z := 0 to ComponentCount-1 do
    begin
    aObj := Components[z];
    if (aObj is TEdit) and (TEdit(aObj).Tag > 0) then
      MyArr[TEdit(aObj).Tag] := StrToInt(TEdit(aObj).Text);
    end;
  showmessage(IntToStr(MyArr[1])
              +#13#10+IntToStr(MyArr[2])
              +#13#10+IntToStr(MyArr[3]));
  end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
luis_figo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Do 25.08.05 13:32 
Hier mal die ganze Anweisung dann könnt ihr es ja für mich basteln ich kenn mich da einfach zu wenig aus!!!


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:
procedure TForm1.RechnenClick(Sender: TObject);
var Gewicht: array[1..4] of real;
    GewichtEdit: Array[1..4] of TEdit;
    i: Integer;
    Schnitt,Summe: real;
    begin



  Gewicht[1]:=StrToFloat(Form1.Gewicht1.Text);
  Gewicht[2]:=StrToFloat(Form1.Gewicht2.Text);
  Gewicht[3]:=StrToFloat(Form1.Gewicht3.Text);
  Gewicht[4]:=StrToFloat(Form1.Gewicht4.Text);


 Summe:=0;
 for i:= 1 to 4 do
  begin
  Summe:=Summe+Gewicht[i];
  Schnitt:=Summe/i;
  end;
  Form1.Schnitt.Text:=FloatToStr(Schnitt);

end;

procedure TForm1.EndeClick(Sender: TObject);
begin
application.terminate
end;

end.


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 25.08.05 13:56 
Hallo,
user profile iconluis_figo hat folgendes geschrieben:
Hier mal die ganze Anweisung dann könnt ihr es ja für mich basteln ich kenn mich da einfach zu wenig aus!!!

... für mich basteln... :arrow: und dann
...ich kenn mich da immer noch zu wenig ... :?
Du hast Beispiele und Tipps bekommen, was verstehst Du nicht?
Was hast Du vor, erkläre es genauer.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 25.08.05 13:59 
user profile iconluis_figo hat folgendes geschrieben:
Hier mal die ganze Anweisung dann könnt ihr es ja für mich basteln ich kenn mich da einfach zu wenig aus!!!
Wir sind doch keine Programmier-Sklaven ;-) Hast Du Gausis Tipp befolgt und mal selber gesucht? Da findet man jede Menge Beispiele.

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

Win XP
D5
BeitragVerfasst: Do 25.08.05 14:02 
Hi,

Wie viele sollen es am ende überhaupt werden ?

Wenn es viele sind, guck dir mal
www.delphi-forum.de/...verwalten_43052.html
an.
Hab sogar ich verstanden :wink:
Versuch es doch mal selbst, die Tips hier sind alle gut.

Arne