Rob Kennedy wrote:
>If you have a TColor value, and you need to use it as a TColorRef, then 
> always use the ColorToRGB function. Nothing in the Windows API uses 
> TColor. The GetRValue, GetBValue, and GetGValue functions are part of 
> the API.

So the following code :

var Red, Green, Blue:integer;
begin
  Red:=GetRValue( ColorToRGB(clBtnFace));
  Green:=GetGValue( ColorToRGB(clBtnFace));
  Blue:=GetBValue( ColorToRGB(clBtnFace));

Is equivalent to or much better than the following code, right?

type
    TRGB = record
        R: Integer;
        G: Integer;
        B: Integer;
end;

function RGBToColor(PR,PG,PB: Integer): TColor;
begin
    Result := TColor((PB * 65536) + (PG * 256) + PR);
end;

function ColorToRGB(PColor: TColor): TRGB;
var
    i: Integer;
begin
    i := PColor;
    Result.R := 0;
    Result.G := 0;
    Result.B := 0;
    while i - 65536 >= 0 do begin i := i -
                             65536; Result.B := Result.B + 1; end;
    while i - 256 >= 0 do begin i := i -
                             256; Result.G := Result.G + 1; end;
    Result.R := i;
end;

function RGBToCol(PRGB: TRGB): TColor;
begin
    Result := RGBToColor(PRGB.R,PRGB.G,PRGB.B);
end;

Now, you can write;
var RGB:TRGB ;

begin
RGB:=ColorToRGB(clBtnFace);


Monir.



----- Original Message ----- 
From: "Rob Kennedy" <[EMAIL PROTECTED]>
To: "Delphi-Talk Discussion List" <[email protected]>
Sent: Monday, March 14, 2005 2:00 AM
Subject: Re: system colours


> Monir-SCS wrote:
> >> Have a look at the ColorToRGB() function from the Graphics unit.
> > 
> > This one works only with system color, right?
> 
> If you pass is a system color, like clBtnFace or clWindow, then it will 
> return the actual color. If you pass it a normal color, like clRed or 
> clGreen, then it will return the original color. As I recall, ColorToRGB 
> will not work on palette colors (in part because the function doesn't 
> know what palette you're using).
> 
> If you have a TColor value, and you need to use it as a TColorRef, then 
> always use the ColorToRGB function. Nothing in the Windows API uses 
> TColor. The GetRValue, GetBValue, and GetGValue functions are part of 
> the API.
> 
> -- 
> Rob
> 
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to