Delphi XE2 FormatDateTime 传递 -693594
我们这里有一点问题。我们已经从 Delphi 2006 升级到 Delphi XE2,并且正在转换我们的代码。
问题是,我们通过应用程序和数据库记录使用值 -693594 来表示无日期(零日期)。在 Delphi 2006 中,FormatDateTime 函数会将其正确格式化为 00/00/0000(给定日期格式为 dd/mm/yyyy)。
然而,在 Delphi XE2 中,他们在 System.SysUtils 的 DateTImeToTimeStamp 函数中添加了对 ValidateTimeStampDate 的调用,这会引发错误“无效浮点操作”。传递任何大于 -693594 的值(例如 -693593)都可以正常工作。
有其他人遇到过这个问题和/或有人知道解决方法吗?
We have a bit of an issue here. We have upgraded from Delphi 2006 to Delphi XE2 and are in the process of converting our code.
The problem is, we use the value -693594 through our application and database records to represent no date (zero date). In Delphi 2006 the FormatDateTime function would correctly format this as 00/00/0000 (given a date format of dd/mm/yyyy).
However in Delphi XE2 they have added a call to ValidateTimeStampDate in the DateTImeToTimeStamp function in System.SysUtils which raises the error "invalid floating point operation". passing anything greater than -693594, such as -693593, works fine.
Has anyone else had this issue and/or does anyone know a work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您真的迫切希望修补回以前的行为,您可以使用类似以下内容:
这适用于 32 位代码。如果新旧函数都驻留在同一可执行模块中,它也适用于 64 位代码。否则跳转距离可能会超出32位整数的范围。如果您的 RTL 驻留在运行时包中,它也将不起作用。这两个限制都可以很容易地解决。
此代码的作用是将所有对
SysUtils.DateTimeToTimeStamp
的调用重新路由到本单元中实现的版本。本单元中的代码只是 XE2 源代码中的PUREPASCAL
版本。满足您评论中概述的需求的唯一其他方法是修改并重新编译 SysUtils 单元本身,但我个人避免这种解决方案。
If you are really desperate to patch back to the previous behaviour you could use something like this:
This will work for 32 bit code. It will also work for 64 bit code provided that both the old and new functions reside in the same executable module. Otherwise the jump distance may exceed the range of a 32 bit integer. It will also not work if your RTL resides in a runtime package. Both of these limitations can be readily remedied.
What this code does is re-route all calls to
SysUtils.DateTimeToTimeStamp
to the version implemented in this unit. The code in this unit is just thePUREPASCAL
version from the XE2 source.The only other approach that meets the needs outlined in your comments is to modify and re-compile the SysUtils unit itself, but I personally avoid that sort of solution.