unit MJBlinkLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Graphics;
type
TBlinkMode = (bmRealBlink, bmFontStyle);
type
TMJBlinkLabel =
class(TLabel)
private
FBlinkMode: TBlinkMode;
FBlink: Boolean;
FBlinkValue: Boolean;
FTimer: TTimer;
FBlinkInterval: Cardinal;
FBlinkFontColor: TColor;
FBlinkFontStyle: TFontStyles;
TmpColor: TColor;
TmpStyle: TFontStyles;
procedure SetBlink(Value: Boolean);
procedure SetBlinkInterval(Value: Cardinal);
{ Private-Deklarationen }
protected
procedure OnTimerEvent(Sender: TObject);
dynamic;
{ Protected-Deklarationen }
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
{ Public-Deklarationen }
published
property BlinkMode: TBlinkMode
read FBlinkMode
write FBlinkMode;
property Blink: Boolean
read FBlink
write SetBlink;
property BlinkInterval: Cardinal
read FBlinkInterval
write SetBlinkInterval;
property BlinkFontColor: TColor
read FBlinkFontColor
write FBlinkFontColor;
property BlinkFontStyle: TFontStyles
read FBlinkFontStyle
write FBlinkFontStyle;
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Extras', [TMJBlinkLabel]);
end;
constructor TMJBLinkLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBlink:=False;
FBlinkInterval:=500;
FBlinkFontColor:=clRed;
FBlinkFontStyle:=[fsBold];
FTimer:=TTimer.Create(Self);
FTimer.OnTimer:=OnTimerEvent;
FTimer.Enabled:=False;
FTimer.Interval:=500;
end;
destructor TMJBLinkLabel.Destroy;
begin
FTimer.Free;
inherited Destroy;
end;
procedure TMJBLinkLabel.OnTimerEvent(Sender: TObject);
begin
FBlinkValue:=not FBlinkValue;
//in dieser Prozedur liegt das Problem
If FBlink = True
then //wird schon zur Entwurfszeit ausgeführt, wenn Blink True ist
begin //ich möchte es aber erst zur Laufzeit Blinken sehen
TmpColor:=Font.Color;
TmpStyle:=Font.Style;
Font.Color:=FBlinkFontColor;
Font.Style:=FBlinkFontStyle;
end
Else
begin
Font.Color:=TmpColor;
Font.Style:=TmpStyle;
end;
end;
procedure TMJBlinkLabel.SetBlink(Value: Boolean);
begin
If FBlink <> Value
then
begin
FBlink:=Value;
FTimer.Enabled:=Value;
end;
end;
procedure TMJBlinkLabel.SetBlinkInterval(Value: Cardinal);
begin
If FBlinkInterval <> Value
then
begin
FBlinkInterval:=Value;
FTimer.Interval:=Value;
end;
end;
end.