DELPHI二维数组设置长度的时候出现了难以理解的问题!急求高人指教!
在另一个UNIT里使用,定义b:b_arr;
在为b初始化长度时,发现b里最多只能容纳730个元素??一超出这个范围就报溢出错误,请教这是怎么回事???
例如:setlength(b,27,27);或者setlength(b,25,29),都没有问题,setlength(28,28);或者setlength(b,29,26);就报错了,'Access violation at address 00401059 in module 'test.exe'. Write of address 0000001D'。没辙了,哪位大人给个办法? 展开
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
b_arr=array of array of double;
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
I,Imax:Integer;
A:b_arr;
begin
Imax:=100;
SetLength(A, Imax) ;
for i := Low(A) to High(A) do
begin
setlength(A[i],Imax);
end;
A[99][90]:=0.55;
end;
end.
{
//可以封装实现多维 现在设置本身就是一个A[100][100]
//10000元素数组
//理论数据最大极限应该 Maxinteger
Unit
System
Category
string handling routines
Delphi syntax:
procedure SetLength(var S; NewLength: Integer);
Description
S is a Delphi string or dynamic-array variable.
NewLength is the new number of characters or elements in S.
For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.
For a long-string or dynamic-array variable, SetLength reallocates the string or array referenced by S to the given length. Existing characters in the string or elements in the array are preserved, but the content of newly allocated space is undefined. The one exception is when increasing the length of a dynamic array in which the elements are types that must be initialized (strings, Variants, Variant arrays, or records that contain such types). When S is a dynamic array of types that must be initialized, newly allocated space is set to 0 or nil.
For dynamic arrays, SetLength may take more than one length parameter (up to the number of array dimensions). Each parameter specifies the number of elements along a particular dimension.
Following a call to SetLength, S is guaranteed to reference a unique string or array梩hat is, a string or array with a reference count of one. If there is not enough memory available to reallocate the variable, SetLength raises an EOutOfMemory exception.
}
//请检查是不是delphi没有更新补丁 我测试用你方法也可以