On 3/11/17, frans via Lazarus <[email protected]> wrote:
> I want to use the color #D8FFF4.
> But the function Color2HTML translate that code to $00D8FFF4#
That makes no sense to me.
#D8FFF4 looks like HTML color coding, so calling ColorToHTML on that
makes no sense (or the name of that makes no sense).
Here's a ColorToHtml function from the SynExportHtml unit that works
correctly (at least in my limited tests):
function ColorToHTML(AColor: TColor): string;
var
RGBColor: TColorRef;
RGBValue: byte;
const
Digits: array[0..15] of char = '0123456789ABCDEF';
begin
Result := '';
case AColor of
clRed: Result := 'red';
clGreen: Result := 'green';
clBlue: Result := 'blue';
clPurple: Result := 'purple';
clYellow: Result := 'yellow';
clBlack: Result := 'black';
clWhite: Result := 'white';
clGray: Result := 'gray';
clMaroon: Result := 'maroon';
clFuchsia: Result := 'fuchsia';
clLime: Result := 'lime';
clNavy: Result := 'navy';
clAqua: Result := 'aqua';
clTeal: Result := 'teal';
clSilver: Result := 'silver';
end;
if (Result <> '') then
Exit;
RGBColor := ColorToRGB(AColor);
Result := '#000000';
{****************}
RGBValue := GetRValue(RGBColor);
if RGBValue > 0 then begin
Result[2] := Digits[RGBValue shr 4];
Result[3] := Digits[RGBValue and 15];
end;
{****************}
RGBValue := GetGValue(RGBColor);
if RGBValue > 0 then begin
Result[4] := Digits[RGBValue shr 4];
Result[5] := Digits[RGBValue and 15];
end;
{****************}
RGBValue := GetBValue(RGBColor);
if RGBValue > 0 then begin
Result[6] := Digits[RGBValue shr 4];
Result[7] := Digits[RGBValue and 15];
end;
end;
Note that the represetation of TColor and HTML color (if you both
write them out as hex) is not in the same order.
Bart
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus-ide.org/listinfo/lazarus