1

以下代码触发EIntOverflow异常。我无法调试它,因为这发生在用户 PC 上,而不是我的。

var

  dwread, iBytesPerMFTRecord : cardinal;

  pc : PChar;

begin

////
// some code here
////

Readfile(hDevice, PChar(pc)^, 100, dwread, nil);


for n:=0 to dwread div iBytesPerMFTRecord -1 do   // `EIntOverflow` exception

似乎 Readfile 正在返回一些奇怪的东西,这会在下一行dwread触发 异常。EIntOverflow

1°)可以返回什么dwread来触发此异常?

2°)如何控制?

4

2 回答 2

4

零我猜:

{$Q+}
procedure TForm1.Button2Click(Sender: TObject);
var
  dw: Cardinal;
  I: Integer;

begin
  dw:= 0;
  I:= dw - 1;   // raised exception class EIntOverflow with message 'Integer overflow'.
  ShowMessage(IntToStr(I));
end;
于 2012-05-03T08:00:28.733 回答
2

从德尔福帮助 - http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.EIntOverflow

EIntOverflow is the exception class for integer calculations whose 
results are too large to fit in the allocated register.

EIntOverflow occurs when data is lost because an integer result 
is too large to retain.

因此您需要更改循环中使用的变量的数据类型以接受更大的值。

于 2012-05-03T07:55:55.203 回答