unit LedAnzeige;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TAnzeige = Integer;
   TLedAnzeige = class(TGraphicControl)
  private
  Anzeigewert: Byte;
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  Procedure Paint; Override;
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
  function GetAnzeige:TAnzeige;
  Procedure SetAnzeige(Anzeige:TAnzeige);
  published
    { Published-Deklarationen }
  property Width default 20;
  property Height default 31;
  Property Anzeige:TAnzeige read GetAnzeige write SetAnzeige default 0;
    end;

procedure Register;

implementation

constructor TLedAnzeige.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Width := 21; // Wiete 21 Pixel
  Height :=31;   // Höhe 31 Pixel
  end;

function TLedAnzeige.GetAnzeige:TAnzeige; // "ANZWIGE" in Opjectinspektor
  begin
  Result := TAnzeige(Anzeigewert);
  end;

Procedure TLedAnzeige.SetAnzeige(Anzeige:TAnzeige); // "ANZEIGE" Setzen
  begin
    Case Anzeige of
    0:  Anzeigewert := 0;
    1:  Anzeigewert := 1;
    2:  Anzeigewert := 2;
    3:  Anzeigewert := 3;
    4:  Anzeigewert := 4;
    5:  Anzeigewert := 5;
    6:  Anzeigewert := 6;
    7:  Anzeigewert := 7;
    8:  Anzeigewert := 8;
    9:  Anzeigewert := 9;
   end;
   If Anzeige >9 then
   Begin
   MessageDLG('Dieser Wert ist unzulässig!  Bitte eine Zahl zwischen 0 und 9 !',
                mtError,[mbOK],0); // MessageDlg wenn Anzeige größer als 9
   exit;
   end
   else
   Begin
   Invalidate; // Komponente neu zeichnen damit die Änderung sofort sichtbar wird
   end
  end;

  procedure TLedAnzeige.Paint; // Diese Procedure zu zeinen der Zahlen
  {Var
  Anzeige:TAnzeige;}
  Begin
  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clWhite;
  Canvas.Brush.Color := clWhite;
  Canvas.Rectangle(0,0,Width,Height);
  Canvas.Pen.Color := clGray;
  Canvas.Brush.Color := clGray;
  Canvas.Rectangle(1,1,Width,Height);
  Canvas.Pen.Color := clSilver;
  Canvas.Brush.Color:= clSilver;
  Canvas.Rectangle(1,1,Width - 1,Height - 1);
  Canvas.Pen.Color := clWhite;
  Canvas.Brush.color := clWhite;
  Canvas.Rectangle(2,2,Width - 2,Height - 2);
  Canvas.Pen.Color := clGray;
  Canvas.Brush.Color := clGray;
  Canvas.Rectangle(2,2,Width - 3,Height - 3);
  Canvas.Pen.COlor := clBlack;
  Canvas.Brush.Color := clBlack;
  Canvas.Rectangle(3,3,Width - 3, Height - 3);
  Canvas.pen.Color := clMaroon;
  // Wagerecht oben
  Canvas.MoveTo(7,4);
  Canvas.LineTo(Width - 7, 4);
  Canvas.MoveTo(6,5);
  Canvas.LineTo(Width - 6, 5);
  Canvas.MoveTo(7,6);
  Canvas.LineTo(Width - 7, 6);
  // Wagerecht Mitte
  Canvas.MoveTo(7,(Height div 2)-1);
  Canvas.LineTo(Width - 7, (Height div 2)-1);
  Canvas.MoveTo(6,(Height div 2));
  Canvas.LineTo(Width - 6, Height div 2);
  Canvas.MoveTo(7,(Height div 2) +1);
  Canvas.LineTo(Width - 7, (Height div 2) +1);
  // Wagerecht Unten
  Canvas.MoveTo(7,Height-7);
  Canvas.LineTo(Width - 7, Height - 7);
  Canvas.MoveTo(6,Height-6);
  Canvas.LineTo(Width - 6, Height - 6);
  Canvas.MoveTo(7,Height-5);
  Canvas.LineTo(Width - 7, Height - 5);
  // Senkrecht oben links
  Canvas.MoveTo(4,7);
  Canvas.LineTo(4, (Height div 2) - 1);
  Canvas.MoveTo(5,6);
  Canvas.LineTo(5, (Height div 2) - 0);
  Canvas.MoveTo(6,7);
  Canvas.LineTo(6, (Height div 2) - 1);
  // Senkrecht oben Rechts
  Canvas.MoveTo(Width - 7,7);
  Canvas.LineTo(Width - 7, (Height div 2) -1);
  Canvas.MoveTo(Width - 6,6);
  Canvas.LineTo(Width - 6, (Height div 2) -0);
  Canvas.MoveTo(Width - 5,7);
  Canvas.LineTo(Width - 5, (Height div 2) -1);
  // Senkrecht links unten
  Canvas.MoveTo(4,Height -8);
  Canvas.LineTo(4, (Height div 2)+1);
  Canvas.MoveTo(5,Height -7);
  Canvas.LineTo(5, (Height div 2)+0);
  Canvas.MoveTo(6,Height -8);
  Canvas.LineTo(6, (Height div 2)+1);
  // Senkrecht Rechts unten
  Canvas.MoveTo(Width-7,Height -8);
  Canvas.LineTo(Width - 7, (Height div 2)+1);
  Canvas.MoveTo(Width-6,Height-7);
  Canvas.LineTo(Width - 6, (Height div 2)+0);
  Canvas.MoveTo(Width-5,Height-8);
  Canvas.LineTo(Width - 5, (Height div 2)+1);

  IF Anzeigewert < 10 then
  Begin
  Canvas.Pen.Color := clRed;
  Case Anzeigewert of
  0:  Begin
      // Wagerecht oben
      Canvas.MoveTo(7,4); //
      Canvas.LineTo(Width - 7, 4);
      Canvas.MoveTo(6,5);
      Canvas.LineTo(Width - 6, 5);
      Canvas.MoveTo(7,6);
      Canvas.LineTo(Width - 7, 6);
      // Wagerecht Unten
      Canvas.MoveTo(7,Height-7);
      Canvas.LineTo(Width - 7, Height - 7);
      Canvas.MoveTo(6,Height-6);
      Canvas.LineTo(Width - 6, Height - 6);
      Canvas.MoveTo(7,Height-5);
      Canvas.LineTo(Width - 7, Height - 5);
      // Senkrecht oben links
      Canvas.MoveTo(4,7);
      Canvas.LineTo(4, (Height div 2) - 1);
      Canvas.MoveTo(5,6);
      Canvas.LineTo(5, (Height div 2) - 0);
      Canvas.MoveTo(6,7);
      Canvas.LineTo(6, (Height div 2) - 1);
      // Senkrecht oben Rechts
      Canvas.MoveTo(Width - 7,7);
      Canvas.LineTo(Width - 7, (Height div 2) -1);
      Canvas.MoveTo(Width - 6,6);
      Canvas.LineTo(Width - 6, (Height div 2) -0);
      Canvas.MoveTo(Width - 5,7);
      Canvas.LineTo(Width - 5, (Height div 2) -1);
      // Senkrecht links unten
      Canvas.MoveTo(4,Height -8);
      Canvas.LineTo(4, (Height div 2)+1);
      Canvas.MoveTo(5,Height -7);
      Canvas.LineTo(5, (Height div 2)+0);
      Canvas.MoveTo(6,Height -8);
      Canvas.LineTo(6, (Height div 2)+1);
      // Senkrecht Rechts unten
      Canvas.MoveTo(Width-7,Height -8);
      Canvas.LineTo(Width - 7, (Height div 2)+1);
      Canvas.MoveTo(Width-6,Height-7);
      Canvas.LineTo(Width - 6, (Height div 2)+0);
      Canvas.MoveTo(Width-5,Height-8);
      Canvas.LineTo(Width - 5, (Height div 2)+1);
      end;

  1:    begin
        // Senkrecht oben Rechts
        Canvas.MoveTo(Width - 7,7);
        Canvas.LineTo(Width - 7, (Height div 2) -1);
        Canvas.MoveTo(Width - 6,6);
        Canvas.LineTo(Width - 6, (Height div 2) -0);
        Canvas.MoveTo(Width - 5,7);
        Canvas.LineTo(Width - 5, (Height div 2) -1);
        // Senkrecht Rechts unten
        Canvas.MoveTo(Width-7,Height -8);
        Canvas.LineTo(Width - 7, (Height div 2)+1);
        Canvas.MoveTo(Width-6,Height-7);
        Canvas.LineTo(Width - 6, (Height div 2)+0);
        Canvas.MoveTo(Width-5,Height-8);
        Canvas.LineTo(Width - 5, (Height div 2)+1);
        end;

  2:      begin
          // Wagerecht oben
          Canvas.MoveTo(7,4);
          Canvas.LineTo(Width - 7, 4);
          Canvas.MoveTo(6,5);
          Canvas.LineTo(Width - 6, 5);
          Canvas.MoveTo(7,6);
          Canvas.LineTo(Width - 7, 6);
          // Wagerecht Mitte
          Canvas.MoveTo(7,(Height div 2)-1);
          Canvas.LineTo(Width - 7, (Height div 2)-1);
          Canvas.MoveTo(6,(Height div 2));
          Canvas.LineTo(Width - 6, Height div 2);
          Canvas.MoveTo(7,(Height div 2) +1);
          Canvas.LineTo(Width - 7, (Height div 2) +1);
          // Wagerecht Unten
          Canvas.MoveTo(7,Height-7);
          Canvas.LineTo(Width - 7, Height - 7);
          Canvas.MoveTo(6,Height-6);
          Canvas.LineTo(Width - 6, Height - 6);
          Canvas.MoveTo(7,Height-5);
          Canvas.LineTo(Width - 7, Height - 5);
          // Senkrecht oben Rechts
          Canvas.MoveTo(Width - 7,7);
          Canvas.LineTo(Width - 7, (Height div 2) -1);
          Canvas.MoveTo(Width - 6,6);
          Canvas.LineTo(Width - 6, (Height div 2) -0);
          Canvas.MoveTo(Width - 5,7);
          Canvas.LineTo(Width - 5, (Height div 2) -1);
          // Senkrecht links unten
          Canvas.MoveTo(4,Height -8);
          Canvas.LineTo(4, (Height div 2)+1);
          Canvas.MoveTo(5,Height -7);
          Canvas.LineTo(5, (Height div 2)+0);
          Canvas.MoveTo(6,Height -8);
          Canvas.LineTo(6, (Height div 2)+1);
          end;

  3:        Begin
            // Senkrecht oben Rechts
            Canvas.MoveTo(Width - 7,7);
            Canvas.LineTo(Width - 7, (Height div 2) -1);
            Canvas.MoveTo(Width - 6,6);
            Canvas.LineTo(Width - 6, (Height div 2) -0);
            Canvas.MoveTo(Width - 5,7);
            Canvas.LineTo(Width - 5, (Height div 2) -1);
            // Senkrecht Rechts unten
            Canvas.MoveTo(Width-7,Height -8);
            Canvas.LineTo(Width - 7, (Height div 2)+1);
            Canvas.MoveTo(Width-6,Height-7);
            Canvas.LineTo(Width - 6, (Height div 2)+0);
            Canvas.MoveTo(Width-5,Height-8);
            Canvas.LineTo(Width - 5, (Height div 2)+1);
            // Wagerecht oben
            Canvas.MoveTo(7,4);
            Canvas.LineTo(Width - 7, 4);
            Canvas.MoveTo(6,5);
            Canvas.LineTo(Width - 6, 5);
            Canvas.MoveTo(7,6);
            Canvas.LineTo(Width - 7, 6);
            // Wagerecht Mitte
            Canvas.MoveTo(7,(Height div 2)-1);
            Canvas.LineTo(Width - 7, (Height div 2)-1);
            Canvas.MoveTo(6,(Height div 2));
            Canvas.LineTo(Width - 6, Height div 2);
            Canvas.MoveTo(7,(Height div 2) +1);
            Canvas.LineTo(Width - 7, (Height div 2) +1);
            // Wagerecht Unten
            Canvas.MoveTo(7,Height-7);
            Canvas.LineTo(Width - 7, Height - 7);
            Canvas.MoveTo(6,Height-6);
            Canvas.LineTo(Width - 6, Height - 6);
            Canvas.MoveTo(7,Height-5);
            Canvas.LineTo(Width - 7, Height - 5);
            end;

  4:          Begin
              // Senkrecht oben Rechts
              Canvas.MoveTo(Width - 7,7);
              Canvas.LineTo(Width - 7, (Height div 2) -1);
              Canvas.MoveTo(Width - 6,6);
              Canvas.LineTo(Width - 6, (Height div 2) -0);
              Canvas.MoveTo(Width - 5,7);
              Canvas.LineTo(Width - 5, (Height div 2) -1);
              // Senkrecht Rechts unten
              Canvas.MoveTo(Width-7,Height -8);
              Canvas.LineTo(Width - 7, (Height div 2)+1);
              Canvas.MoveTo(Width-6,Height-7);
              Canvas.LineTo(Width - 6, (Height div 2)+0);
              Canvas.MoveTo(Width-5,Height-8);
              Canvas.LineTo(Width - 5, (Height div 2)+1);
              // Wagerecht Mitte
              Canvas.MoveTo(7,(Height div 2)-1);
              Canvas.LineTo(Width - 7, (Height div 2)-1);
              Canvas.MoveTo(6,(Height div 2));
              Canvas.LineTo(Width - 6, Height div 2);
              Canvas.MoveTo(7,(Height div 2) +1);
              Canvas.LineTo(Width - 7, (Height div 2) +1);
              // Senkrecht oben links
              Canvas.MoveTo(4,7);
              Canvas.LineTo(4, (Height div 2) - 1);
              Canvas.MoveTo(5,6);
              Canvas.LineTo(5, (Height div 2) - 0);
              Canvas.MoveTo(6,7);
              Canvas.LineTo(6, (Height div 2) - 1);
              end;

  5:          Begin
              // Senkrecht oben links
              Canvas.MoveTo(4,7);
              Canvas.LineTo(4, (Height div 2) - 1);
              Canvas.MoveTo(5,6);
              Canvas.LineTo(5, (Height div 2) - 0);
              Canvas.MoveTo(6,7);
              Canvas.LineTo(6, (Height div 2) - 1);
              // Wagerecht oben
              Canvas.MoveTo(7,4);
              Canvas.LineTo(Width - 7, 4);
              Canvas.MoveTo(6,5);
              Canvas.LineTo(Width - 6, 5);
              Canvas.MoveTo(7,6);
              Canvas.LineTo(Width - 7, 6);
              // Wagerecht Mitte
              Canvas.MoveTo(7,(Height div 2)-1);
              Canvas.LineTo(Width - 7, (Height div 2)-1);
              Canvas.MoveTo(6,(Height div 2));
              Canvas.LineTo(Width - 6, Height div 2);
              Canvas.MoveTo(7,(Height div 2) +1);
              Canvas.LineTo(Width - 7, (Height div 2) +1);
              // Wagerecht Unten
              Canvas.MoveTo(7,Height-7);
              Canvas.LineTo(Width - 7, Height - 7);
              Canvas.MoveTo(6,Height-6);
              Canvas.LineTo(Width - 6, Height - 6);
              Canvas.MoveTo(7,Height-5);
              Canvas.LineTo(Width - 7, Height - 5);
              // Senkrecht Rechts unten
              Canvas.MoveTo(Width-7,Height -8);
              Canvas.LineTo(Width - 7, (Height div 2)+1);
              Canvas.MoveTo(Width-6,Height-7);
              Canvas.LineTo(Width - 6, (Height div 2)+0);
              Canvas.MoveTo(Width-5,Height-8);
              Canvas.LineTo(Width - 5, (Height div 2)+1);
              end;
  6:            Begin
                // Senkrecht oben links
                Canvas.MoveTo(4,7);
                Canvas.LineTo(4, (Height div 2) - 1);
                Canvas.MoveTo(5,6);
                Canvas.LineTo(5, (Height div 2) - 0);
                Canvas.MoveTo(6,7);
                Canvas.LineTo(6, (Height div 2) - 1);
                // Wagerecht oben
                Canvas.MoveTo(7,4);
                Canvas.LineTo(Width - 7, 4);
                Canvas.MoveTo(6,5);
                Canvas.LineTo(Width - 6, 5);
                Canvas.MoveTo(7,6);
                Canvas.LineTo(Width - 7, 6);
                // Wagerecht Mitte
                Canvas.MoveTo(7,(Height div 2)-1);
                Canvas.LineTo(Width - 7, (Height div 2)-1);
                Canvas.MoveTo(6,(Height div 2));
                Canvas.LineTo(Width - 6, Height div 2);
                Canvas.MoveTo(7,(Height div 2) +1);
                Canvas.LineTo(Width - 7, (Height div 2) +1);
                // Wagerecht Unten
                Canvas.MoveTo(7,Height-7);
                Canvas.LineTo(Width - 7, Height - 7);
                Canvas.MoveTo(6,Height-6);
                Canvas.LineTo(Width - 6, Height - 6);
                Canvas.MoveTo(7,Height-5);
                Canvas.LineTo(Width - 7, Height - 5);
                // Senkrecht Rechts unten
                Canvas.MoveTo(Width-7,Height -8);
                Canvas.LineTo(Width - 7, (Height div 2)+1);
                Canvas.MoveTo(Width-6,Height-7);
                Canvas.LineTo(Width - 6, (Height div 2)+0);
                Canvas.MoveTo(Width-5,Height-8);
                Canvas.LineTo(Width - 5, (Height div 2)+1);
                // Senkrecht links unten
                Canvas.MoveTo(4,Height -8);
                Canvas.LineTo(4, (Height div 2)+1);
                Canvas.MoveTo(5,Height -7);
                Canvas.LineTo(5, (Height div 2)+0);
                Canvas.MoveTo(6,Height -8);
                Canvas.LineTo(6, (Height div 2)+1);
                end;

  7:              Begin
                  Canvas.MoveTo(Width - 7,7);
                  Canvas.LineTo(Width - 7, (Height div 2) -1);
                  Canvas.MoveTo(Width - 6,6);
                  Canvas.LineTo(Width - 6, (Height div 2) -0);
                  Canvas.MoveTo(Width - 5,7);
                  Canvas.LineTo(Width - 5, (Height div 2) -1);
                  // Senkrecht Rechts unten
                  Canvas.MoveTo(Width-7,Height -8);
                  Canvas.LineTo(Width - 7, (Height div 2)+1);
                  Canvas.MoveTo(Width-6,Height-7);
                  Canvas.LineTo(Width - 6, (Height div 2)+0);
                  Canvas.MoveTo(Width-5,Height-8);
                  Canvas.LineTo(Width - 5, (Height div 2)+1);
                  // Wagerecht oben
                  Canvas.MoveTo(7,4);
                  Canvas.LineTo(Width - 7, 4);
                  Canvas.MoveTo(6,5);
                  Canvas.LineTo(Width - 6, 5);
                  Canvas.MoveTo(7,6);
                  Canvas.LineTo(Width - 7, 6);
                  end;

  8:                Begin
                    // Wagerecht oben
                    Canvas.MoveTo(7,4);
                    Canvas.LineTo(Width - 7, 4);
                    Canvas.MoveTo(6,5);
                    Canvas.LineTo(Width - 6, 5);
                    Canvas.MoveTo(7,6);
                    Canvas.LineTo(Width - 7, 6);
                    // Wagerecht Mitte
                    Canvas.MoveTo(7,(Height div 2)-1);
                    Canvas.LineTo(Width - 7, (Height div 2)-1);
                    Canvas.MoveTo(6,(Height div 2));
                    Canvas.LineTo(Width - 6, Height div 2);
                    Canvas.MoveTo(7,(Height div 2) +1);
                    Canvas.LineTo(Width - 7, (Height div 2) +1);
                    // Wagerecht Unten
                    Canvas.MoveTo(7,Height-7);
                    Canvas.LineTo(Width - 7, Height - 7);
                    Canvas.MoveTo(6,Height-6);
                    Canvas.LineTo(Width - 6, Height - 6);
                    Canvas.MoveTo(7,Height-5);
                    Canvas.LineTo(Width - 7, Height - 5);
                    // Senkrecht oben links
                    Canvas.MoveTo(4,7);
                    Canvas.LineTo(4, (Height div 2) - 1);
                    Canvas.MoveTo(5,6);
                    Canvas.LineTo(5, (Height div 2) - 0);
                    Canvas.MoveTo(6,7);
                    Canvas.LineTo(6, (Height div 2) - 1);
                    // Senkrecht oben Rechts
                    Canvas.MoveTo(Width - 7,7);
                    Canvas.LineTo(Width - 7, (Height div 2) -1);
                    Canvas.MoveTo(Width - 6,6);
                    Canvas.LineTo(Width - 6, (Height div 2) -0);
                    Canvas.MoveTo(Width - 5,7);
                    Canvas.LineTo(Width - 5, (Height div 2) -1);
                    // Senkrecht links unten
                    Canvas.MoveTo(4,Height -8);
                    Canvas.LineTo(4, (Height div 2)+1);
                    Canvas.MoveTo(5,Height -7);
                    Canvas.LineTo(5, (Height div 2)+0);
                    Canvas.MoveTo(6,Height -8);
                    Canvas.LineTo(6, (Height div 2)+1);
                    // Senkrecht Rechts unten
                    Canvas.MoveTo(Width-7,Height -8);
                    Canvas.LineTo(Width - 7, (Height div 2)+1);
                    Canvas.MoveTo(Width-6,Height-7);
                    Canvas.LineTo(Width - 6, (Height div 2)+0);
                    Canvas.MoveTo(Width-5,Height-8);
                    Canvas.LineTo(Width - 5, (Height div 2)+1);
                    end;
  9:                  Begin
                      // Wagerecht oben
                      Canvas.MoveTo(7,4);
                      Canvas.LineTo(Width - 7, 4);
                      Canvas.MoveTo(6,5);
                      Canvas.LineTo(Width - 6, 5);
                      Canvas.MoveTo(7,6);
                      Canvas.LineTo(Width - 7, 6);
                      // Wagerecht Mitte
                      Canvas.MoveTo(7,(Height div 2)-1);
                      Canvas.LineTo(Width - 7, (Height div 2)-1);
                      Canvas.MoveTo(6,(Height div 2));
                      Canvas.LineTo(Width - 6, Height div 2);
                      Canvas.MoveTo(7,(Height div 2) +1);
                      Canvas.LineTo(Width - 7, (Height div 2) +1);
                      // Wagerecht Unten
                      Canvas.MoveTo(7,Height-7);
                      Canvas.LineTo(Width - 7, Height - 7);
                      Canvas.MoveTo(6,Height-6);
                      Canvas.LineTo(Width - 6, Height - 6);
                      Canvas.MoveTo(7,Height-5);
                      Canvas.LineTo(Width - 7, Height - 5);
                      // Senkrecht oben links
                      Canvas.MoveTo(4,7);
                      Canvas.LineTo(4, (Height div 2) - 1);
                      Canvas.MoveTo(5,6);
                      Canvas.LineTo(5, (Height div 2) - 0);
                      Canvas.MoveTo(6,7);
                      Canvas.LineTo(6, (Height div 2) - 1);
                      // Senkrecht oben Rechts
                      Canvas.MoveTo(Width - 7,7);
                      Canvas.LineTo(Width - 7, (Height div 2) -1);
                      Canvas.MoveTo(Width - 6,6);
                      Canvas.LineTo(Width - 6, (Height div 2) -0);
                      Canvas.MoveTo(Width - 5,7);
                      Canvas.LineTo(Width - 5, (Height div 2) -1);
                      // Senkrecht Rechts unten
                      Canvas.MoveTo(Width-7,Height -8);
                      Canvas.LineTo(Width - 7, (Height div 2)+1);
                      Canvas.MoveTo(Width-6,Height-7);
                      Canvas.LineTo(Width - 6, (Height div 2)+0);
                      Canvas.MoveTo(Width-5,Height-8);
                      Canvas.LineTo(Width - 5, (Height div 2)+1);
                      end;
      end;   // end Case
  end;  // end if
 end; // end Procedure 

  procedure Register;
begin
  RegisterComponents('Elektro', [TLedAnzeige]);
end;

end.
