德尔福最大的错误或限制.常数整数值?

参见英文答案 > 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;

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...