TMyLED2 = class(TCustomControl)
private
fTimer : TTimer;
fShape : TShape;
fPulseInterval : integer;
fOnColor : TColor;
fOffColor : TColor;
fShapeType : TShapeType;
// fPen : TPen; // <------------------ REMOVE
function GetPulseInterval : integer;
procedure SetPulseInterval(Value : integer);
function GetOnColor : TColor;
procedure SetOnColor(Value : TColor);
function GetOffColor : TColor;
procedure SetOffColor(Value : TColor);
function GetShapeType : TShapeType;
procedure SetShapeType(Value : TShapeType);
function GetPen : TPen;
procedure SetPen(Value : TPen);
protected
procedure MyTimer(Sender: TObject);
public
constructor Create(AOwner : TComponent); override;
procedure Pulse;
published
property Pen : TPen read GetPen write SetPen;
property Shape : TShapeType read GetShapeType write SetShapeType;
property PulseInterval : integer read GetPulseInterval write SetPulseInterval;
property OnColor : TColor read GetOnColor write SetOnColor;
property OffColor : TColor read GetOffColor write SetOffColor;
end;
constructor TMyLED2.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
fPulseInterval := 100;
fOnColor := clLime;
fOffColor := clBlue;
fShapeType := stRectangle;
// fPen := TPen.Create; // <--------------- REMOVE
Width := 50;
Height := 50;
fTimer := TTimer.Create(self);
with fTimer do
begin
Enabled := false;
Interval := fPulseInterval;
OnTimer := @MyTimer;
end;
fShape := TShape.Create(self);
with fShape do
begin
Align := alClient;
Shape := fShapeType;
Parent := self;
Brush.Color := fOffColor;
end;
//Constraints.MaxHeight := 23;
Constraints.MinHeight := 10;
//Constraints.MaxWidth := 23;
Constraints.MinWidth := 10;
//SetBounds(0, 0, 20, 20);
end;
function TMyLED2.GetPen : TPen;
begin
// result := fPen; // <------------- use the Shape's Pen
result := FShape.Pen;
end;
procedure TMyLED2.SetPen(Value : TPen);
begin
// If fPen <> Value then // <--------------- use the Shape's Pen
if GetPen <> Value then
begin
// fShape.Pen := fPen;
fShape.Pen.Assign(Value);
end;
end;