- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的项目中使用此代码:
var
P: TPoint;
MyControl.Perform(WM_LBUTTONDOWN, 0, Longint(PointToSmallPoint(P)));
编译器给我一个警告:
[Warning]: Unsafe typecast of 'TSmallPoint' to 'Integer'
但是,Controls.pas
中使用了相同的代码没有任何警告 - 例如在 TControl.BeginDrag
方法中:
....
Perform(WM_LBUTTONUP, 0, Longint(PointToSmallPoint(P)));
我在 Controls.pas
单元中没有看到任何 {$warnings off}
。
为什么编译器会警告我,但会跳过 Controls.pas
的警告?
这段代码不安全吗?
编辑:在我的项目选项 -> 编译器消息 -> 不安全类型转换已选中(默认情况下未选中)。
也许这就是@David 和@Ken 无法重现警告的原因。
最佳答案
这是因为您在“项目”->“选项”->“编译器消息”中检查了不安全类型转换
警告。取消选中此选项是安全的(如其上方的不安全类型
和不安全代码
。(见下文。)
我无法重现该警告,因为我未检查不安全类型转换。它不再适用。 (在开发 Delphi for .NET 时,它被添加到 Delphi 6 或 7 中以实现 .net 兼容性,以便更轻松地编写同时适用于 .NET 和 Win32 的代码;由于 Delphi for .NET 产品已停产,该警告(以及上面的两个)不再适用)。这三个警告中的“unsafe”使用了.NET中“unsafe”的含义,意思是“非托管”。
来自 Delphi 7 帮助文件(搜索“编译器更改”)(强调我的):
The Delphi dcc32 compiler now supports three additional compiler warnings: Unsafe_Type, Unsafe_Code, and Unsafe_Cast. These warnings are disabled by default, but can be enabled with the compiler directive {$WARN UNSAFE_CODE ON}, compiler command line switch (dcc32 -W+UNSAFE_CODE), and, in the IDE, on the Project|Options|Compiler Messages page.
This feature is intended to help you port your code to the managed execution environment of Microsoft's .NET platform. In a managed execution environment, "unsafe" means the operation cannot be verified during the static analysis performed by the Just In Time (JIT) compiler. Such code might pose a security risk, since there is not enough information for the JIT compiler to verify its runtime behavior. Examples of unsafe code include pointer operations and memory overwrites.
关于delphi - 警告 : Unsafe typecast of 'TSmallPoint' to 'Integer' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14076750/
我在我的项目中使用此代码: var P: TPoint; MyControl.Perform(WM_LBUTTONDOWN, 0, Longint(PointToSmallPoint(P)));
我是一名优秀的程序员,十分优秀!