参见英文答案 >
E2099 Overflow in conversion or arithmetic operation1个
const minDriveFreeSpace: Int64 = 1024*1024*1024*99;
和
var minDriveFreeSpace: Int64; begin minDriveFreeSpace := 1024*1024*1024*99;
会发出:
[dcc32 Error] DataStoreLocator.pas(92): E2099 Overflow in conversion or arithmetic operation
这是Delphi最大的错误还是限制.常数整数值?
解决方法
您需要在右侧将至少一个值强制转换为Int64.例如,这两个在XE6上编译得非常好:
const minDriveFreeSpace = Int64(1024) * 1024 * 1024 * 99; var minDriveFreeSpace2: Int64; begin minDriveFreeSpace2 := Int64(1024)*1024*1024*99;
请注意,它可以是任何一个施放的右值.例如,这也同样有效:
const minDriveFreeSpace = 1024 * 1024 * 1024 * Int64(99);
这在Delphi language guide中有记录(虽然相当差) – 强调我的:
In general,arithmetic operations on integers return a value of type Integer,which is equivalent to the 32-bit LongInt. Operations return a value of type Int64 only when performed on one or more Int64 operands. Therefore,the following code produces incorrect results:
var I: Integer; J: Int64; ... I := High(Integer); J := I + 1;
To get an Int64 return value in this situation,cast I as Int64:
... J := Int64(I) + 1;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。