范围检查错误和Delphi 7.0 [英] Range Check Error and Delphi 7.0

查看:123
本文介绍了范围检查错误和Delphi 7.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花了一周的时间检查并修复了我的程序通过FastMM4导致的内存泄漏后,我终于测试了在另一台PC上运行我的程序。现在,我收到范围检查错误。我已经花了数小时在网上进行相关研究,但似乎没有一个能满足我的需求。我的程序符合运行时错误选项范围检查的要求。因此,我知道这就是为什么我得到此错误,但我需要确切地知道为什么会引起该错误。

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.

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

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?

推荐答案

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

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;

或者对于动态数组:

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.

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

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

由Ken提示,文档指出了什么受范围检查选项的影响如下:

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


在{$ R +}状态,所有数组和
字符串索引表达式已验证
是否在定义的
范围内,并且所有对标量
和子范围变量的赋值都将检查为
在范围内。

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.

这篇关于范围检查错误和Delphi 7.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆