📄 agentlamp.pas
字号:
//内线灯相关操作
unit AgentLamp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons, ExtCtrls, Types, Data;
type
TAgentLamp = class
public
//建构函数
constructor Create(Sender : TWinControl; mLamp : Integer; mLeft : Integer; mTop : Integer; mRowCount : 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;
public
//通道状态,用于保存所有内线通道的状态数据
DataList : TAgentList;
private
AgentLampArr : array of TShape;
AgentIndexArr : array of TLabel;
AgentCommentArr : array of TLabel;
AgentConnectArr : array of TLabel;
Count : Integer;
ArrLeft : Integer;
ArrTop : Integer;
ptTmp : TPoint;
end;
const
LampWidth = 15;
LampHeight = 15;
LineHeight = 22;
implementation
//初始化灯
constructor TAgentLamp.Create(Sender : TWinControl; mLamp : Integer; mLeft : Integer; mTop : Integer; mRowCount : Integer);
var
i : Integer;
begin
Count := mLamp; //灯的数目
ArrLeft := mLeft; //灯的左边坐标
ArrTop := mTop; //灯的顶部坐标
DataList := TAgentList.Create(mLamp, mRowCount);
SetLength(AgentLampArr, mLamp);
SetLength(AgentIndexArr, mLamp);
SetLength(AgentCommentArr, mLamp);
SetLength(AgentConnectArr, mLamp);
//设置各个shape的位置
for i := 0 to mLamp - 1 do
begin
AgentLampArr[i] := TShape.Create(Sender);
AgentIndexArr[i] := TLabel.Create(Sender);
AgentCommentArr[i] := TLabel.Create(Sender);
AgentConnectArr[i] := TLabel.Create(Sender);
With AgentLampArr[i] do
begin
Parent := Sender;
Brush.Color := clLime;
Shape := stCircle;
Top := mTop + i * (LineHeight);
Left := mLeft;
Width := LampWidth;
Height := LampHeight;
Visible := True;
end;
With AgentIndexArr[i] do
begin
Parent := Sender;
Top := mTop + 2 + i * (LineHeight);
Left := mLeft + 20;
Caption := inttostr(i);
Visible := True;
end;
With AgentConnectArr[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 AgentCommentArr[i] do
begin
Parent := Sender;
Top := mTop + 2 + i * (LineHeight);
Left := mLeft + 40;
Caption := '';
Width := 150;
Visible := True;
end;
end;
end;
destructor TAgentLamp.Destroy;
var
i : Integer;
begin
DataList.Destroy;
for i := 0 to Count - 1 do
begin
AgentLampArr[i].Free;
AgentIndexArr[i].Free;
AgentConnectArr[i].Free;
AgentCommentArr[i].Free;
end;
end;
procedure TAgentLamp.SetLampGreen(Index : Integer);
begin
if Index < Count then
begin
AgentLampArr[Index].Brush.Color := clLime;
AgentConnectArr[Index].Visible := False;
AgentConnectArr[Index].Caption := '';
AgentCommentArr[Index].Caption := '';
end;
end;
procedure TAgentLamp.SetLampRed(Index : Integer; Connect : Integer; Comment : String);
begin
if Index < Count then
begin
AgentLampArr[Index].Brush.Color := clRed;
if Index <> Connect then
begin
AgentConnectArr[Index].Visible := True;
end;
if Connect < 10 then
begin
AgentConnectArr[Index].Caption := ' ' + inttostr(Connect);
end
else
begin
AgentConnectArr[Index].Caption := inttostr(Connect);
end;
AgentCommentArr[Index].Caption := Comment;
end;
end;
procedure TAgentLamp.SetLampComment(Index : Integer; Comment : String);
begin
if Index < Count then
AgentCommentArr[Index].Caption := Comment;
end;
function TAgentLamp.GetLampPoint(Index : Integer) : TPoint;
begin
if Index < Count then
begin
ptTmp.X := ArrLeft + 7;
ptTmp.Y := ArrTop + 7 + Index * LineHeight;
result := ptTmp;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -