Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

颜色转换数字越界 #43

Closed
qq143626 opened this issue Jan 25, 2022 · 7 comments
Closed

颜色转换数字越界 #43

qq143626 opened this issue Jan 25, 2022 · 7 comments

Comments

@qq143626
Copy link

在UI.Util.pas文件中,涉及到16进制颜色值转换TAlphaColor方法中,应该用StrToInt64Def而不是StrToIntDef,24位颜色值前面加上FF之后,会超出Int32的最大值,导致出错软件崩溃

@KngStr
Copy link
Collaborator

KngStr commented Feb 12, 2022

Int32是4字节,TAlphaColor也是4字节
不会溢出。
你有崩溃的例子嘛?

@qq143626
Copy link
Author

UI.Utils.pas中的HtmlColorToColor方法中,如果颜色指定为color=''#303030''或color=''303030''时,会分别调用到调用下面两行语句
第878行Result := StrToIntDef('$ff' + Copy(S, 2, Length(S) - 1), 0)
第903行if (Length(s) = 6) then result := StrToIntDef('$ff' + s, 0)
StrToIntDef方法会将$ff303030转为-13619152,而返回值TAlphaColor的类型是type Cardinal,数字越界导致的程序崩溃
建议这两个方法将'$ff'改成'$',或者用StrToUIntDef

@qq143626
Copy link
Author

另外这个错误只有在动态赋值的时候才会出现,设计期直接指定的话运行没问题

@KngStr
Copy link
Collaborator

KngStr commented Feb 13, 2022

ShowMessage(IntToHex(HtmlColorToColor('#303030')));
未测试到崩溃,最终的数值也不错。
不过确实是用StrToUIntDef好些,已更新。
感谢反馈

@KngStr KngStr closed this as completed Feb 13, 2022
@qq143626
Copy link
Author

是我的错,程序崩溃是因为在FormCreate中
,属于Application.Error,让我误以为是崩溃,在ButtonView1Click中只是Error,所以只是弹出错误框,我之前都是在窗体显示前修改的HtmlText,没有测试窗体显示后修改HtmlText,所以才说崩溃
QQ截图20220213151834
QQ截图20220213151932

@KngStr
Copy link
Collaborator

KngStr commented Feb 13, 2022

这就奇怪了。我也经常这样赋值,没遇到过错误

@qq143626
Copy link
Author

那就不清楚了,要不就是delphi版本的问题,要不就是编译开关的问题,我这边是xe11,编译开关没改过

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants