EricTaylor
asked on
Converting Delphi color to integer color
I have colors stored in the database as strings that contain delphi colors, e.g. $00FFFF80, $000000FF, etc. I have a component that expects an integer color rather than a string. I've tried to convert the existing colors with this code, but, since the colors produced are incorrect, I'm apparently doing something wrong. Appreciate any insight. Thanks.
function HexToTColor(sColor: string): TColor;
begin
// sColor begins with $00 so trim sColor to the last 6 chars
if length(sColor) < 6 then sColor := 'FFFFFF'
else sColor := rightStr(sColor, 6);
Result := RGB(StrToInt('$'+Copy(sColor, 1, 2)),
StrToInt('$'+Copy(sColor, 3, 2)),
StrToInt('$'+Copy(sColor, 5, 2))
);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.