Board index » delphi » Changing the color of the list of component on a panel

Changing the color of the list of component on a panel

I need to change the color of a group of components at run time. The
components may include TEdit, TMemo, TlookupCombo... and they are sitting on
a TPanel.
The most efficient way is the iterate throught the list of components and
change their color property using

for c:=0 to Panels.ComponentCount-1
begin
    Panels.Components[c].Color:=clRed
end

However, the color property of the component is protected at TComponent
level.

How can I solve this problem?

Thanks
SIA

 

Re:Changing the color of the list of component on a panel


On Thu, 20 Jan 2000 12:26:23 +0800 STC wrote:

Quote
> I need to change the color of a group of components at run time. The
> components may include TEdit, TMemo, TlookupCombo... and they are sitting on
> a TPanel.

> for c:=0 to Panels.ComponentCount-1
> begin
>     Panels.Components[c].Color:=clRed
> end

> the color property of the component is protected at TComponent level.
> How can I solve this problem?

Do a type cast for every component like
  if Panels.Components[c] is TEdit then
    TEdit(Panels.Components[c]).Color:= clRed else
  if Panels.Components[c] is TMemo then
    TMemo(Panels.Components[c]).Color:= clRed else
...

Bye, Udo

Other Threads