The implementation of the Screen's OnActiveControlChange event handler calls the custom "EnterColor" procedure for the currently focused data entry control after a call to "ExitColor" for the previuosly selected one:
procedure TMainForm.EnterColor(Sender: TWinControl) ;Delphi's RTTI methods are hidden inside the "TypInfo" unit - make sure you add "TypInfo" to the uses clause of the unit where RTTI methods are used.
begin
if Sender <> nil then
begin
if IsPublishedProp(Sender,'Color') then
begin
originalColor := GetOrdProp(Sender,'Color') ;
SetOrdProp(Sender,'Color', focusColor) ;
end;
end;
end;
First you make sure that the "Color" property is exposed by "Sender" using the "IsPublishedProp" procedure. Next, you store the original background color value using the "GetOrdProp" procedure. Finally, the "SetOrdProp" changes the background color to the color we specified to be used for focused controls.
You also need to make sure that the control that had focus has its background color restored:
procedure TMainForm.ExitColor(Sender: TWinControl) ;That's all folks!
begin
if Sender <> nil then
begin
if IsPublishedProp(Sender,'Color') then
begin
SetOrdProp(Sender,'Color',originalColor) ;
end;
end;
end;
Make sure you download the full source code.


