[Lazarus] ColotToRGB in GTK apps

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Jul 26 21:47:07 CEST 2008

On Sat, 26 Jul 2008 21:55:03 +0300
Valdas Jank┼źnas <skroblas at erdves.lt> wrote:

> Hello,
>   i trying get R G B values of system color "clBackground" (and
> others). So i use ColorToRGB function (app compiled with gtk2 widget
> set), but I get values that differs from actual color of form face. I
> found that these values match to values defined in unit "GTKGlobals"
> in array "SysColorMap". Is this function not yet implemented or this
> is a bug?
> Lazarus svn 15819; fpc 2.2.0 i386; Linux i386 Kubuntu 8.04
> P.S.
>   I tried get rgb values with code:
> function SpalvaToRGB(const color: TColor): TColor;
> var
>    drobe: TBitmap;
> begin
>      drobe:=TBitmap.Create;
>      drobe.Height:=1;
>      drobe.Width:=1;
>      drobe.Canvas.Brush.Color:=color;
>      drobe.Canvas.FillRect(0, 0, 1, 1);
>      result:=drobe.Canvas.Pixels[0, 0];
>      drobe.Free;
> end;
>   but when I every time call this function passing clBackground,
> clForm or clColorDesktop as "color" i get random value. Why?

These constants depend on widget class and user theme. For example a
button has a different background than a form. And many themes use
images or gradients or transparency and do not define a default color.
I don't know what you are trying to achieve, but maybe you can use the
functions of the lcl themes unit.


More information about the Lazarus mailing list