[Lazarus] How to obtain the color of a component?

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Fri Oct 21 10:43:31 CEST 2011


On Fri, Oct 21, 2011 at 10:35 AM, Paul Ishenin <ip at kmiac.ru> wrote:
> GetColor should return the color assigned to a control. In other case you
> will have many problems with object inspector and form saving.

Indeed ... In this case I propose something like this:

function TControl.GetColorResolvingParent: TColor;
begin
  if Color = clDefault then
    Result := GetDefaultColor(dctBrush)
  else
    Result := Color;
end;

function TControl.GetRGBColor: TColor;
begin
    Result := ColorToRGB(GetColorResolvingParent);
end;

What do you think? Using the if ... else everywhere that wants to
obtain the color is really not great. Proposals for naming this?

-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list