unit EditColorHandler;
interface
Uses Forms, Classes, Controls, Graphics, StdCtrls;
Const
_ActiveColor = $009BF5FD;
_DefaultColor = clWhite;
type
TEditColorHandler =
class(TObject)
private
FActiveControl: TWinControl;
FActive: Boolean;
procedure SetActive(
const Value: Boolean);
public
procedure doActiveControlChange(Sender: TObject);
property Active: Boolean
read FActive
write SetActive;
end;
Var
AppEditColorHandler: TEditColorHandler;
implementation
procedure TEditColorHandler.doActiveControlChange(Sender: TObject);
begin
if Assigned(FActiveControl)
and FActiveControl.HandleAllocated
and
(FActiveControl
is TEdit)
then
TEdit(FActiveControl).Color := _DefaultColor;
FActiveControl := Screen.ActiveControl;
if FActiveControl
is TEdit
then
TEdit(FActiveControl).Color := _ActiveColor;
end;
procedure TEditColorHandler.SetActive(
const Value: Boolean);
begin
if FActive <> Value
then
begin
FActive := Value;
if FActive
then
Screen.OnActiveControlChange := doActiveControlChange
else
Screen.OnActiveControlChange :=
nil;
end;
end;
initialization
AppEditColorHandler := TEditColorHandler.Create;
finalization
AppEditColorHandler.Free;
end.