⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmleds.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
     FSize := ls13x21;
     FLEDSpace := 1;
     NumDigits := 2;

     ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
     if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
destructor TMMLedPanel.Destroy;
begin
     DestroyAllDigits;
     inherited Destroy;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
{$IFDEF WIN32}
{$IFDEF DELPHI3}
procedure TMMLedPanel.GetChildren(Proc: TGetChildProc; Root: TComponent);
{$ELSE}
procedure TMMLedPanel.GetChildren(Proc: TGetChildProc);
{$ENDIF}
begin
end;
{$ENDIF}

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLEDPanel.CMColorChanged(var Message: TMessage);
{$IFDEF BUILD_ACTIVEX}
var
   i: integer;
{$ENDIF}
begin
   inherited;

   {$IFDEF BUILD_ACTIVEX}
   for i := 0 to FNumDigits-1 do FDigits[i].Color := Color;
   {$ENDIF}
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.Change;
begin
   if (csLoading in ComponentState) or
      (csReading in ComponentState) then exit;

   if assigned(FOnChange) then FOnChange(Self);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
function TMMLedPanel.CreateDigit: TMMLedDigit;
begin
     Result := TMMLedDigit.Create(Self);
     Result.Parent := Self;
     Result.CascadeValues := True;
     Result.Enabled := Enabled;
     Result.DigitSize := FSize;
     {$IFDEF BUILD_ACTIVEX}
     Result.Color := Color;
     {$ENDIF}
     Result.InactiveColor := FInactiveColor;
     Result.LEDColor := FLEDColor;
     Result.DrawInactive := FDrawInactive;
     Result.ParentShowHint := False;
     Result.OnClick := BtnClick;
     Result.OnDblClick := BtnDblClick;
     Result.OnMouseDown := MsDown;
     Result.OnMouseMove := MsMove;
     Result.OnMouseUp := MsUp;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.CreateAllDigits;
Var
   i: integer;

begin
     for i := 0 to FNumDigits-1 do
     begin
          FDigits[i] := CreateDigit;
          if i > 0 then FDigits[i-1].Connect := FDigits[i];
     end;
     FDigits[0].ZeroBlank := False;
     FDigits[0].Value := FValue;
     SetZeroBlank(FZeroBlank);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.DestroyAllDigits;
Var
   i: integer;

begin
     for i := 0 to FNumDigits-1 do
     begin
          FDigits[i].Free;
          FDigits[i] := Nil;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.BtnClick(Sender: TObject);
begin
     Click;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.BtnDblClick(Sender: TObject);
begin
     DblClick;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.MsDown(Sender: TObject; Button: TMouseButton;
                             Shift: TShiftState; X, Y: Integer);
begin
     MouseDown(Button, Shift, X, Y);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.MsUp(Sender: TObject; Button: TMouseButton;
                           Shift: TShiftState; X, Y: Integer);
begin
     MouseUp(Button, Shift, X, Y);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.MsMove(Sender: TObject; Shift: TShiftState;
                             X, Y: Integer);
begin
     MouseMove(Shift, X, Y);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetBounds(aLeft, aTop, aWidth, aHeight: Integer);
var
  W, H: Integer;

begin
     W := aWidth;
     H := aHeight;
     AdjustSize (W, H);
     inherited SetBounds (aLeft, aTop, W, H);
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.AdjustSize (Var W, H: Integer);
Var
   i: integer;
   aLeft: integer;

begin
     if (FDigits[0] = Nil) or (csLoading in ComponentState) or
        (csReading in ComponentState) then exit;

     W := (((FDigits[0].Width + FLEDSpace) * FNumDigits) + 2 * BevelExtend) - FLEDSpace;
     H := FDigits[0].Height + 2 * BevelExtend;
     aLeft := BevelExtend;
     for i := FNumDigits-1 downTo 0 do
     begin
          FDigits[i].SetBounds (aLeft,BevelExtend, FDigits[0].Width, FDigits[0].Height);
          inc(aLeft, FDigits[0].Width + FLEDSpace);
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.AdjustBounds;
var
  W, H: Integer;

begin
     W := Width;
     H := Height;
     AdjustSize (W, H);
     if (W <> Width) or (H <> Height) then
        inherited SetBounds(Left, Top, W, H)
     else Invalidate;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.WMSize(var Message: TWMSize);
begin
     inherited;
     AdjustBounds;
     Message.Result := 0;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLEDPanel.Changed;
begin
     AdjustBounds;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetNumDigits(aValue: integer);
begin
     if (aValue <> FNumDigits) AND (aValue > 0) AND (aValue < 10) then
     begin
        DestroyAllDigits;
        FNumDigits := aValue;
        CreateAllDigits;
        AdjustBounds;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetLEDSpace(aValue: integer);
begin
     if (aValue <> FLEDSpace) AND (aValue > 0) then
     begin
          FLEDSpace := aValue;
          AdjustBounds;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetLEDColor(aValue: TColor);
Var
   i: integer;

begin
     if (aValue <> FLEDColor) then
     begin
          FLEDColor := aValue;
          for i := 0 to FNumDigits-1 do
              FDigits[i].LEDColor := FLEDColor;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetInactiveColor(aValue: TColor);
Var
   i: integer;

begin
     if (aValue <> FInactiveColor) then
     begin
          FInactiveColor := aValue;
          for i := 0 to FNumDigits-1 do
              FDigits[i].InactiveColor := FInactiveColor;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetDrawInactive(aValue: Boolean);
Var
   i: integer;

begin
     if (FDrawInactive <> aValue) then
     begin
          FDrawInactive := aValue;
          for i := 0 to FNumDigits-1 do
              FDigits[i].DrawInactive := FDrawInactive;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetEnabled(aValue: Boolean);
Var
   i: integer;

begin
     if (aValue <> inherited Enabled) then
     begin
          inherited Enabled := aValue;
          for i := 0 to FNumDigits-1 do
              FDigits[i].Enabled := Enabled;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
function TMMLEDPanel.GetEnabled: Boolean;
begin
     Result := inherited Enabled;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetZeroBlank(aValue: Boolean);
Var
   i: Longint;
   j: integer;

begin
   FZeroBlank := aValue;
   if FZeroBlank then
   begin
      i := 10;
      j := 1;
      while (i < abs(FValue)) AND (j < FNumDigits-1) do
      begin
         FDigits[j].ZeroBlank := False;
         inc(j);
         i := i * 10;
      end;
      for j := j to FNumDigits-1 do FDigits[j].ZeroBlank := True;
   end
   else for i := 1 to FNumDigits-1 do FDigits[i].ZeroBlank := False;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLEDPanel.SetSize(aValue: TMMLEDSize);
Var
   i: integer;
begin
     if (FSize <> aValue) then
     begin
          FSize := aValue;
          for i := 0 to FNumDigits-1 do
              FDigits[i].DigitSize := FSize;
          AdjustBounds;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetValue(aValue: Longint);
begin
     aValue := MinMax(aValue, FMinValue, FMaxValue);
     if (aValue <> FValue) then
     begin
          FValue := aValue;

          SetZeroBlank(FZeroBlank);

          FDigits[0].Value := abs(FValue);
          if (FValue < 0) then FDigits[FNumDigits-1].DisplayType := ltMinus
          else FDigits[FNumDigits-1].DisplayType := ltDigit;
          Change;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetMinValue(aValue: Longint);
begin
     if (aValue <> FMinValue) then
     begin
          FMinValue := aValue;
          if (FValue < FMinValue) then Value := FMinValue;
          Invalidate;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.SetMaxValue(aValue: Longint);
begin
     if (aValue <> FMaxValue) then
     begin
          FMaxValue := aValue;
          if (FValue > FMaxValue) then Value := FMaxValue;
          Invalidate;
     end;
end;

{-- TMMLEDPanel ----------------------------------------------------------}
procedure TMMLedPanel.Loaded;
begin
     inherited Loaded;

     AdjustBounds;
end;

{== TMMLEDSpin ===========================================================}
constructor TMMLEDSpin.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);

     ControlStyle := ControlStyle - [csSetCaption];

     FButton := TMMSpinButton.Create(Self);

     FLEDPanel := TMMLEDPanel.Create(Self);
     FLEDPanel.Parent := Self;
     FLEDPanel.TabStop := False;
     FLEDPanel.OnClick := BtnClick;
     FLEDPanel.OnDblClick := BtnDblClick;
     FLEDPanel.OnMouseDown := MsDown;
     FLEDPanel.OnMouseMove := MsMove;
     FLEDPanel.OnMouseUp := MsUp;
     FLEDPanel.OnChange := ChildChange;
     FLEDPanel.Color := clBlack;
     FLEDPanel.ParentShowHint := False;

     FButton.Parent := Self;
     FButton.FocusControl := Self;
     FButton.Bevel.OnChange := GetChanged;

     FButton.TabOrder := 0;
     FButton.OnUpClick := UpClick;
     FButton.OnDownClick := DownClick;
     FButton.OnChange := ChildChange;
     FButton.ParentShowHint := False;


     ParentColor := True;
     TabStop := True;
     FSpace := 2;
     FLEDPanel.OnResize := GetChanged;
     AdjustBounds;

     ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
     if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;

{-- TMMLEDSpin -----------------------------------------------------------}
destructor TMMLEDSpin.Destroy;
begin
     FLEDPanel.OnResize := Nil;
     FLEDPanel.Free;
     FButton.Free;
     inherited Destroy;
end;

{-- TMMLEDSpin -----------------------------------------------------------}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -