TStringGrid 单元格的范围检查是否有效?

Does range checking on TStringGrid cells work?

下面是一个简单的 Delphi 表单应用程序的代码,它为包含单元格的指定 TStringGrid 设置超出范围的单元格值。

运行 当计数器 i 高于1.

在项目选项中启用了范围检查,我已经尝试 运行使用和不使用 {R+} 编译器指令编译程序。

为什么没有范围检查错误?

我在 Windows 7(64 位)上使用 Delphi7 运行ning。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
{$R+} 
procedure TForm1.StringGrid1Click(Sender: TObject);
var
    i : Integer;
begin
    Form1.StringGrid1.ColCount := 2;
    Form1.StringGrid1.RowCount := 3;
    for i := 0 to Form1.StringGrid1.RowCount do begin
        Form1.StringGrid1.Cells[0,i+1] := IntToStr(i);
    end;
end;

end.

来自documentation强调):

The $R directive enables or disables the generation of range-checking code. 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. If a range check fails, an ERangeError exception is raised (or the program is terminated if exception handling is not enabled).

TStringGrid 单元格引用不属于要进行范围检查的变量和赋值类型。