Einzelnen Beitrag anzeigen

steenvoortl

Registriert seit: 13. Nov 2009
Ort: Duisburg
4 Beiträge
 
Lazarus
 
#1

case mit einem in einem String gespeicherten Variablennamen

  Alt 13. Nov 2009, 13:19
Hallo =)
Ich habe eine kleine Frage... kann man den Quelltext mit einer Prozedur vereinfachen, damit der case-Teil nicht 27-mal geschrieben werden muss?
Habe schon im Forum gesucht, aber nichts gefunden.

Delphi-Quellcode:
with ImCube.Canvas do begin
  case FUL of
    1: Brush.Color := clWhite;
    2: Brush.Color := clYellow;
    3: Brush.Color := clGreen;
    4: Brush.Color := clBlue;
    5: Brush.Color := clRed;
    6: Brush.Color := $000080FF;
  end;
  Rectangle(10, 64, 60, 114);
  //[...] und das jetzt bei 27 Variablen
  case RDR of
    1: Brush.Color := clWhite;
    2: Brush.Color := clYellow;
    3: Brush.Color := clGreen;
    4: Brush.Color := clBlue;
    5: Brush.Color := clRed;
    6: Brush.Color := $000080FF;
  end;
  Polygon([Point(196,128),Point(196,178),Point(214,160),Point(214,110)]);
end;
Ich dachte an so ein Konstrukt:

Delphi-Quellcode:
procedure TForm1.SetColor(Seite: string);
begin
  with ImCube.Canvas do begin
    case Seite of
      1: Brush.Color := clWhite;
      2: Brush.Color := clYellow;
      3: Brush.Color := clGreen;
      4: Brush.Color := clBlue;
      5: Brush.Color := clRed;
      6: Brush.Color := $000080FF;
    end;
  end;
end;
Delphi-Quellcode:
SetColor('FUL');
ImCube.Canvas.Rectangle(10, 64, 60, 114);
//[...]
SetColor('RDR');
ImCube.Canvas.Polygon([Point(196,128),Point(196,178),Point(214,160),Point(214,110)]);
end;
Aber das funktioniert so nicht, weil ich es nicht hinkriege, dass case die Variable ausliest, deren Name in dem String gespeichert ist und nicht versucht, den String selbst auszulesen.

Habt ihr irgendwelche Tipps?

Danke im Voraus
steenvoortl
  Mit Zitat antworten Zitat