{十六进值字符串转换成LongInt值} function HexStrToInt(S: String): LongInt; var I: Integer; begin Result := 0; for I := 1 to Length(S) do begin if S[I] in ['0'..'9'] then Result := Result * 16 + (Integer(S[I]) - 48) else if S[I] in ['A'..'F'] then Result := Result * 16 + (Ord(S[I]) - 55); end; end;
function HexStrToInt(S: String): LongInt;
var
I: Integer;
begin
Result := 0;
for I := 1 to Length(S) do
begin
if S[I] in ['0'..'9'] then
Result := Result * 16 + (Integer(S[I]) - 48)
else if S[I] in ['A'..'F'] then
Result := Result * 16 + (Ord(S[I]) - 55);
end;
end;
稍微不同的是Tcolor类型上来说一个枚举,而且还有点差异,所以要这样用
StringToColor('HTML的色彩字符串');
前面那位老大,写函数比较辛苦吧!嗬嗬,你不知道吗?StrToInt这个函数在编译器中也是用到的,Delphi的源程序中的$XXXX的16进制的数字都是用这StrToInt函数转换的,呵呵。
前面那位老大,写函数比较辛苦吧!嗬嗬,你不知道吗?StrToInt这个函数在编译器中也是用到的,Delphi的源程序中的$XXXX的16进制的数字都是用这StrToInt函数转换的,呵呵。
小弟有一点不明白,为什么用StringToColor转换出来的颜色和Html的颜色会有些不一样呢?例如:FFFF7B应为黄色,可转换出来确是青色,而有些颜色却能转换正确。还差一点就给分。请高手指点。
delphi color: BGRweb delphi
---------------------------
#1D2736 #36271D
例如:#FF 00 00 反过来是 $00 00 FF
而:#12 34 56 反过来是 $56 34 12