Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 10.07.02 18:35 
Hallo !!!!

Ich habe auf meinem Formular viele Labels (Label1, Label2, Label3......)
In meinem Programm werden viele Variablen abgefragt, und ich will, dass das dann in den Labels ausgegeben wird.
Also konkret:

Ich arbeite in einer for-Schleife. Für die Variable x werden die werte 1 bis 30 eingesetzt. dann werden verschiedene Variablen geprüft und dann soll das ergebnis in dem passenden Label (Labelx) ausgegeben werden.

Wie muss das ausschauen ???

Etwa so ???
ausblenden Quelltext
1:
2:
3:
4:
 for schleife mit x
if schleifen

Label[x].caption := ergebnis der if schleifen

_________________
In the beginning was the word.
And the word was content-type: text/plain.
DaDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win 2000, Linux
D2005 Prof
BeitragVerfasst: Mi 10.07.02 19:26 
Hi ...

Spontan fällt mir dazu folgende Lösung ein:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TFormxxx.FillLabel(LabelIndex: Integer; Value: string);
var
  TC: TComponent;
begin
  TC := FindComponent('Label' + IntToStr(LabelIndex));
  if Assigned(TC) then
    TLabel(TC).Caption := Value;
end;

Beispiel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TFormxxx.Button1Click(Sender: TObject);
var
  X: Integer;
  Wert: Integer;
begin
  for X := 1 to 30 do begin
    Wert := 2 * X; // oder so ...
    FillLabel(X, IntToStr(Wert)); // oder "FloatToStr()" oder "Format()"...
  end;
end;


Sven
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 11.07.02 00:53 
Hallo,

vieleicht hilft dir auch die Idee des Komponentenarrays aus diesem Thread weiter.

Gruß
Klabautermann
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 11.07.02 18:16 
Danke an euch !!! Der Threat von Kalbauterman hat mir zwar nicht wirlich geholfen. Das nadre dafür aber !!!! :idea:

_________________
In the beginning was the word.
And the word was content-type: text/plain.