范围检查错误和Delphi 7.0

发布于 2024-10-27 13:06:36 字数 366 浏览 3 评论 0原文

在花了一周时间通过 FastMM4 检查并修复程序的内存泄漏后,我终于在另一台 PC 上测试运行了我的程序。现在,我收到“范围检查错误”。我花了几个小时在网上研究这个问题,但他们似乎都没有给我我想要的东西。我的程序符合运行时错误选项范围检查。所以,我知道这就是我收到错误的原因,但我需要确切地知道引发错误的原因。

该程序是在 XP 上用 Delphi 7.0 编译的。测试PC是Windows 7。一旦启动,我的程序就开始通过串行端口进行通信,然后出现“范围检查错误”消息框。当我停止串行通信时,没有“范围检查错误”框。这是什么意思以及我该如何解决它?我正在寻找简单的策略。我知道我可能会花几天时间逐行检查。

由于值分配不当或访问数组的不可访问索引而导致的“范围检查错误”。我说得对吗?

After spending a week checking and fixing my program for memory leaks through FastMM4, I finally test ran my program on a different PC. Now, I am getting "Range Check Error." I have spent hours researching online about this, but none of them seem to give me what I am looking for. My program was complied with the Runtime Error option Range Check. So, I know that's why I am getting the error, but I needed to know exactly why the error is raised.

The program was compiled on XP with Delphi 7.0. The testing PC is a Windows 7. As soon as it starts up, my program begins to communicate through serial port and then followed by "Range Check Error" message boxes. When I stop the serial communication, there are no "Range Check Error" boxes. What does this mean and how do I go about resolving it? I am looking for simple strategy. I know I could spend days checking line by line.

"Range Check Error" caused by improper assignment of values or accessing inaccessible index of an array. Am I correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷子口的你 2024-11-03 13:06:36

您对范围检查错误的理解是正确的。当您访问数组边界之外的数组时,就会出现它们。例如:

type
  TFixedArray = array [0..41] of Integer;
var
  a: TFixedArray;
begin
  a[42] := 1+2;//!! this is a range check error !!
end;

或者对于动态数组:

var
  a: array of Integer;
begin
  SetLength(a, 666);
  a[665] := 12;//this is fine
  a[666] := 42;//!! this is a range check error !!
end;

我已经用赋值来说明了这一点,但是读取索引越界的数组也会产生范围错误。

范围错误应报告发生该错误的地址,然后您可以使用地图文件将其转换为代码位置。如果您使用 madExcept 或类似的工具,那就更好了。


更新

在 Ken 的提示下,文档说明了范围检查的影响选项如下:

在{$R+}状态下,所有数组和
字符串索引表达式是
经验证在定义范围内
边界以及对标量的所有赋值
并检查子范围变量
在范围内。

Your understanding of range check errors is correct. They arise when you access an array outside it's bounds. For example:

type
  TFixedArray = array [0..41] of Integer;
var
  a: TFixedArray;
begin
  a[42] := 1+2;//!! this is a range check error !!
end;

Or for a dynamic array:

var
  a: array of Integer;
begin
  SetLength(a, 666);
  a[665] := 12;//this is fine
  a[666] := 42;//!! this is a range check error !!
end;

I've illustrated this with assignment, but reading an array with an index out of bounds will also produce a range error.

The range error should report an address at which it occurs which you can then translate into a code location with your map file. Even better would be if you were using madExcept or some such tool.


UPDATE

Prompted by Ken, the documentation states what is affected by the range checking option as follows:

In the {$R+} state, all array and
string-indexing expressions are
verified as being within the defined
bounds, and all assignments to scalar
and subrange variables are checked to
be within range.

葬﹪忆之殇 2024-11-03 13:06:36

在阅读了有关“范围检查错误”概念的其他信息后,我认为导致该场景中的“范围检查错误”的原因是:
分配访问程序读取的串口的变量是16字节(或更小)类型,并且程序读取的串口超出了该变量的限制。
请注意,[当我停止串行通信时,没有“范围检查错误”框。],这应该使所有事情都清楚。

Having read other information about the concept of "range check error", I believe that the reason for causing the "range check error" in this scenerio is that:
the variable assigning to access the serial port the program reads is an 16-bytes(or smaller) type, and the serial port the program reads exceeds the limitation of the variable.
Notice that [When I stop the serial communication, there are no "Range Check Error" boxes.], this should make all things clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文