Autor Beitrag
gih9
Hält's aus hier
Beiträge: 14

Win2000
D5 Prof.
BeitragVerfasst: Mo 08.03.04 16:09 
Hallo,

ich hab folgendes Problem. Ich zwölf Panles welche entweder rot oder grün sind, die Farbe hängt vun einem boolean Variable ab. Jede 5 sekunden ändert diese Variable und dann muss ich alle zwölf Panels neu malen. Dazu benutze ich jetzt folgenden code
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:
23:
24:
25:
26:
  for i := 1 to 12 do
    if sgResults.Cells[i,1] = '-1' then
      begin
        if i = 1 then
          begin
            fDisplay.pError1.Color := clRed;
            fDisplay.pError1.Caption := '-1'
          end;
        if i = 2 then
          begin
            fDisplay.pError2.Color := clRed;
            fDisplay.pError2.Caption := '-1'
          end;
        if i = 3 then
          begin
            fDisplay.pError3.Color := clRed;
            fDisplay.pError3.Caption := '-1'
          end;
        if i = 4 then
          begin
            fDisplay.pError4.Color := clRed;
            fDisplay.pError4.Caption := '-1'
          end;
         .
         .
         .

Der code ist noch länger aber man erkennt hoffentlich das Problem. Meine Frage ist ob und wie man dan vereinfachen könnte. Ungefähr so stell ich mir das vor.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  for i := 1 to 12 do
    if sgResults.Cells[i,1] = '-1' then
      begin
        fDisplay.pError[i].Color := clRed;
        fDisplay.pError[i].Caption := '-1'
      end
    else
      begin
        fDisplay.pError[i].Color := clGreen;
        fDisplay.pError[i].Caption := '0'
      end;

Ich weiss dass das nicht funktioniert, ist nur eine Idee wie es gehen könnte.

Das Problem is fast wie bei folgendem Beitrag www.delphi-forum.de/viewtopic.php?t=13929, nur will ich halt das Panel verändern und nicht etwas auslesen.

Danke

gih9

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.
OlafSt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 486
Erhaltene Danke: 99

Win7, Win81, Win10
Tokyo, VS2017
BeitragVerfasst: Mo 08.03.04 16:25 
What about this:

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:
23:
var
  tp:TPanel;
  s:string;
  TC: TColor;
begin
  for i:=1 to 10 do
  begin
    if sg.Cells[][]='-1' then
    begin
      s:='-1';
      TC:=clRed;
    end
    else
    begin
      ...
    end;
    tp:=FindComponent('Panel'+IntToStr(i)) as TPanel;
    with tp do
    begin
      Color:=TC
      Caption:=s;
    end;
end;


Fehlt nur noch der richtige Panel-Name.. Die sind doch hoffentlich durchnummeriert :shock:


Zuletzt bearbeitet von OlafSt am Mo 08.03.04 16:26, insgesamt 1-mal bearbeitet
gih9 Threadstarter
Hält's aus hier
Beiträge: 14

Win2000
D5 Prof.
BeitragVerfasst: Mo 08.03.04 16:26 
Ich wusste dass es nicht alzu schwierig sein könnte :)
Versuchs gleich mal.
gih9 Threadstarter
Hält's aus hier
Beiträge: 14

Win2000
D5 Prof.
BeitragVerfasst: Mo 08.03.04 16:44 
hab's jetzt so gemacht
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:
23:
24:
procedure TfOverview.WriteToDisplay;
  var i : byte;
      tp:TPanel;
begin
  for i := 1 to 12 do
    if sgResults.Cells[i,1] = '-1' then
      begin
        tp:=FindComponent('pError'+IntToStr(i)) as TPanel;
        with fDisplay,tp do
          begin
            Color:= clRed;
            Caption := '-1'
          end
      end
    else
      begin
        tp:=FindComponent('pError'+IntToStr(i)) as TPanel;
        with fDisplay,tp do
          begin
            Color:= clGreen;
            Caption := '0'
          end
      end
end;

Jetzt hab ich jedoch noch ein anderes Problem und krieg ich bei folgender Zeile
ausblenden Delphi-Quelltext
1:
tp:=FindComponent('pError'+IntToStr(i)) as TPanel;					

tp=nil. Das kommt warscheinlich daher dass die Panel auf einer anderen Form sind. Denk ich mal.
Hat da einer ne Idee??

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: Mo 08.03.04 21:45 
ausblenden Delphi-Quelltext
1:
tp:=Form2.FindComponent('pError'+IntToStr(i)) as TPanel;					


natürlcih musst du nohc

ausblenden Delphi-Quelltext
1:
2:
implemation
uses Unit2;


oben reinschreiben...

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)