📄 digitlamp.pas
字号:
//数字线灯相关操作
unit DigitLamp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons, ExtCtrls, Types, Data;
type
TDigitLamp = class
public
constructor Create(Sender : TWinControl; mLamp : Integer; mLeft : Integer; mTop : Integer);
destructor Destroy;
procedure SetLampGreen(Index : Integer);
procedure SetLampRed(Index : Integer; Connect : Integer; Comment : String);
procedure SetLampComment(Index : Integer; Comment : String);
function GetLampPoint(Index : Integer) : TPoint;
procedure SetLampHint(Index : Integer; mHint : String);
procedure AddLampHint(Index : Integer; mHint : String);
public
DataList : TDigitList; //数字线状态
Count : Integer;
private
DigitLampArr : array of TShape;
DigitIndexArr : array of TLabel;
DigitCommentArr : array of TLabel;
DigitConnectArr : array of TLabel;
ArrLeft : Integer;
ArrTop : Integer;
ptTmp : TPoint;
end;
const
LampWidth = 15;
LampHeight = 15;
LineHeight = 66;
implementation
constructor TDigitLamp.Create(Sender : TWinControl; mLamp : Integer; mLeft : Integer; mTop : Integer);
var
i : Integer;
begin
Count := mLamp;
ArrLeft := mLeft;
ArrTop := mTop;
DataList := TDigitList.Create(mLamp );
SetLength(DigitLampArr, mLamp);
SetLength(DigitIndexArr, mLamp);
SetLength(DigitCommentArr, mLamp);
SetLength(DigitConnectArr, mLamp);
for i := 0 to mLamp - 1 do
begin
DigitLampArr[i] := TShape.Create(Sender);
DigitIndexArr[i] := TLabel.Create(Sender);
DigitCommentArr[i] := TLabel.Create(Sender);
DigitConnectArr[i] := TLabel.Create(Sender);
With DigitLampArr[i] do
begin
Parent := Sender;
Brush.Color := clLime;
Shape := stCircle;
Top := mTop + i * (LineHeight);
Left := mLeft;
Width := LampWidth;
Height := LampHeight;
Visible := True;
ShowHint := True;
Hint := '空闲';
end;
With DigitIndexArr[i] do
begin
Parent := Sender;
Top := mTop + 2 + i * (LineHeight);
Left := mLeft - 10;
Caption := inttostr(i);
Visible := True;
end;
With DigitConnectArr[i] do
begin
Parent := Sender;
Top := mTop + 3 + i * (LineHeight);
Left := mLeft + 3;
Color := clRed;
Font.Name := 'Ms Serif';
Font.Size := 6;
Caption := '';
Visible := False;
end;
With DigitCommentArr[i] do
begin
Parent := Sender;
Top := mTop + 2 + i * (LineHeight);
Left := mLeft - 100;
Caption := '';
Width := 85;
Visible := True;
Alignment := taRightJustify;
end;
end;
end;
destructor TDigitLamp.Destroy;
var
i : Integer;
begin
DataList.Destroy;
for i := 0 to Count - 1 do
begin
DigitLampArr[i].Free;
DigitIndexArr[i].Free;
DigitConnectArr[i].Free;
DigitCommentArr[i].Free;
end;
end;
procedure TDigitLamp.SetLampGreen(Index : Integer);
begin
if Index < Count then
begin
DigitLampArr[Index].Brush.Color := clLime;
DigitConnectArr[Index].Visible := False;
DigitConnectArr[Index].Caption := '';
DigitCommentArr[Index].Caption := '';
end;
end;
procedure TDigitLamp.SetLampRed(Index : Integer; Connect : Integer; Comment : String);
begin
if Index < Count then
begin
DigitLampArr[Index].Brush.Color := clRed;
DigitConnectArr[Index].Visible := False;
if Connect < 10 then
DigitConnectArr[Index].Caption := ' ' + inttostr(Connect)
else
DigitConnectArr[Index].Caption := inttostr(Connect);
DigitCommentArr[Index].Caption := Comment;
end;
end;
procedure TDigitLamp.SetLampComment(Index : Integer; Comment : String);
begin
if Index < Count then
DigitCommentArr[Index].Caption := Comment;
end;
function TDigitLamp.GetLampPoint(Index : Integer) : TPoint;
begin
if Index < Count then
begin
ptTmp.X := ArrLeft + 7;
ptTmp.Y := ArrTop + 7 + Index * LineHeight;
result := ptTmp;
end;
end;
procedure TDigitLamp.SetLampHint(Index : Integer; mHint : String);
begin
if Index < Count then
begin
DigitLampArr[Index].Hint := mHint;
end;
end;
procedure TDigitLamp.AddLampHint(Index : Integer; mHint : String);
begin
if Index < Count then
begin
DigitLampArr[Index].Hint := DigitLampArr[Index].Hint + mHint;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -