Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Eine Schleife für die Labels mit Variablenzuordnung(Array)? (https://www.delphipraxis.net/45284-eine-schleife-fuer-die-labels-mit-variablenzuordnung-array.html)

Hallo_Thomas 3. Mai 2005 14:42


Eine Schleife für die Labels mit Variablenzuordnung(Array)?
 
Ich habe jetzt schon eine versuche hintermir, haber wie schaffe ich es unten den Text zsammenzufassen?



die Lange Form
Delphi-Quellcode:
       Form1.Label192.Caption:= IntToStr(Counte[0]) ;
       Form1.Label193.Caption:= IntToStr(Counte[1]) ;
       Form1.Label194.Caption:= IntToStr(Counte[2]) ;
       Form1.Label195.Caption:= IntToStr(Counte[3]) ;
       Form1.Label196.Caption:= IntToStr(Counte[4]) ;
       Form1.Label197.Caption:= IntToStr(Counte[5]) ;
       Form1.Label198.Caption:= IntToStr(Counte[6]) ;
       Form1.Label199.Caption:= IntToStr(Counte[7]) ;
       Form1.Label200.Caption:= IntToStr(Counte[8]) ;
       Form1.Label201.Caption:= IntToStr(Counte[9]) ;
Mein Fehlgeschlagener versuch, da ändert sich im Label gar nix:
Delphi-Quellcode:
begin
 for x:=0 to 9 do
  for i:=192 to 201 do
(FindComponent('form1.Label'+IntToStr(i)) as TLabel).Caption:=IntToStr(Counte[x]);

Waldteufel 3. Mai 2005 14:47

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Hi.

Die innere Schleife wird ja 10x durchlaufen... ;-)

Besser so:

Delphi-Quellcode:
for i:=0 to 9 do
  (FindComponent('Label'+IntToStr(i + 192)) as TLabel).Caption:=IntToStr({ edit: NICHT Counte[x], sondern} Counte[i]);
//edit: So ein blöder Programmierfehler... :wall:

Hallo_Thomas 3. Mai 2005 14:56

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Nein, die Labels


funktionieren auch nicht bei

Delphi-Quellcode:
(FindComponent('form1.Label'+IntToStr(i)) as TLabel).Caption:=IntToStr(Counte[x]);

freak4fun 3. Mai 2005 14:59

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Könnte es vielleicht am Counte[x] liegen? Einfach mal mit i versuchen. Bei mir funktioniert es mit i.

MfG
freak

Hallo_Thomas 3. Mai 2005 15:08

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Also so sieht der Spass ganz aus, wo ich die Labels einzeln angegangen bin(siehe oben) hats geklappt




Delphi-Quellcode:
begin
  for i:=0 to 9 do
  Counte[i]:=0;
  for pl0 := Form1.Anzeige.count-1 DownTo 0 do
    begin
      if StrToInt(Form1.Anzeige.Items[pl0]) in [0,10,20,30] then
      Counte[0] := 0
      else Inc(Counte[0]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [1,11,21,31] then
      Counte[1] := 0
      else Inc(Counte[1]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [2,12,22,32] then
      Counte[2] := 0
      else Inc(Counte[2]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [3,13,23,33] then
      Counte[3] := 0
      else Inc(Counte[3]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [4,14,24,34] then
      Counte[4] := 0
      else Inc(Counte[4]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [5,15,25,35] then
      Counte[5] := 0
      else Inc(Counte[5]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [6,16,26,36] then
      Counte[6] := 0
      else Inc(Counte[6]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [7,17,27] then
      Counte[7] := 0
      else Inc(Counte[7]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [8,18,28] then
      Counte[8] := 0
      else Inc(Counte[8]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [9,19,29] then
      Counte[9] := 0
      else Inc(Counte[9]);
      (FindComponent('form1.Label'+IntToStr(i+192)) as TLabel).Caption:=IntToStr(Counte[i]);
      end;
 end;

@ freak4fun , nee das will auch nicht funken

freak4fun 3. Mai 2005 15:19

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Hier mein Code.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 1 to 5 do
  (FindComponent('Label'+IntToStr(i)) as TLabel).Caption := IntToStr(47);
end;
Poste doch mal deinen Versuch, mit zusammenfassung.

MfG
freak

Hallo_Thomas 3. Mai 2005 15:24

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
@freak4fun


Du hast rechts einen "stabilen Wert", was bei mir ja nicht der Fall ist, diese Array will nicht harmonieren mit meinem zeugs.

freak4fun 3. Mai 2005 15:30

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Delphi-Quellcode:
      else Inc(Counte[9]);
      (FindComponent('form1.Label'+IntToStr(i+192)) as TLabel).Caption:=IntToStr(Counte[i]);
      end;

Das i scheint mit undefiniert. Das ist kein Schleifenzähler mehr, einfach ein fester Wert.
Was bekommst du denn als ergebnis?

MfG freak

Hallo_Thomas 3. Mai 2005 15:37

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
meinst Du so
Delphi-Quellcode:
begin
  i:=0  ;
  for i:=0 to 9 do
  Counte[i]:=0;

aber wird i nicht durch

Delphi-Quellcode:
for i:=0 to 9 do
definiert?

freak4fun 3. Mai 2005 15:42

Re: Eine Schleife für die Labels mit Variablenzuordnung(Arra
 
Zitat:

Zitat von Hallo_Thomas
Also so sieht der Spass ganz aus, wo ich die Labels einzeln angegangen bin(siehe oben) hats geklappt




Delphi-Quellcode:
begin
  for i:=0 to 9 do
  Counte[i]:=0;
  for pl0 := Form1.Anzeige.count-1 DownTo 0 do
    begin
      if StrToInt(Form1.Anzeige.Items[pl0]) in [0,10,20,30] then
      Counte[0] := 0
      else Inc(Counte[0]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [1,11,21,31] then
      Counte[1] := 0
      else Inc(Counte[1]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [2,12,22,32] then
      Counte[2] := 0
      else Inc(Counte[2]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [3,13,23,33] then
      Counte[3] := 0
      else Inc(Counte[3]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [4,14,24,34] then
      Counte[4] := 0
      else Inc(Counte[4]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [5,15,25,35] then
      Counte[5] := 0
      else Inc(Counte[5]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [6,16,26,36] then
      Counte[6] := 0
      else Inc(Counte[6]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [7,17,27] then
      Counte[7] := 0
      else Inc(Counte[7]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [8,18,28] then
      Counte[8] := 0
      else Inc(Counte[8]);
      if StrToInt(Form1.Anzeige.Items[pl0]) in [9,19,29] then
      Counte[9] := 0
      else Inc(Counte[9]);
      (FindComponent('form1.Label'+IntToStr(i+192)) as TLabel).Caption:=IntToStr(Counte[i]);
                                            ^
                                     Das i mein ich.        
      end;
 end;

Entschuldige, ich hab mich falsch ausgedrückt. Bei der markierten Stelle(ganz unten), das i ist immer EIN konstannter Wert. Schau es dir mal an. :)

MfG
freak


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:00 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz