HTML Color 采用十六进制表示颜色,其格式为RGB,而Tcolor的格式是GBR。如果把HTML颜色转为Tcolor,需要转换其格式。
比如: HTML Color: #123456
转为Tcolor,则为:$563412, 把其转为Integer值,即为Tcolor值。
function TForm1.htmlColor2color( hColor : string ) : Integer;
var
s, c : string;
begin
s := hColor.Trim;
if ( s.Chars[ 0 ] ).IsNumber then
s := s.PadLeft( 6, '0' )
else
s := s.Substring( 1 ).PadLeft( 6, '0' );
// html color : rgb tcolor : gbr
Result := ('$' + s.Substring( 4, 2 ) + s.Substring( 2, 2 ) + s.Substring( 0, 2 )).ToInteger;
end;
以上在 Delphi Berlin 10.1 测试通过。