DELPHI二维数组设置长度的时候出现了难以理解的问题!急求高人指教!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DELPHI二维数组设置长度的时候出现了难以理解的问题!急求高人指教!相关的知识,希望对你有一定的参考价值。
在定义数据结构的UNIT里定义了这样一个TYPE:b_arr:array of array of double;
在另一个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没有更新补丁 我测试用你方法也可以
参考技术B 二维需要循环设你这么设,只是设的某一维的数组个数
二维数组的语法
知识点
二维数组语法
int [][] arrr=new int[2][];
定义了二维数组的长度,但是一维数组长度没有定义,一
维数组没有申请内存空间为null。
int [][] arr=new int[2][3];
定义了一维数组和二维数组的长度。一维数组分配了 内存
空间。一维数组的长度为3,一维数组的元素默认为0。
二维数组也支持静态初始化:
String [][] arr={{"a","b","c"},{"d","e"}};
package day20181029;
import java.util.Scanner;
/**
* 白日依山尽
* 黄河入海流
* 欲穷千里目
* 更上一层楼
* @author Administrator
*
*/
public class PrintStrDemo {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
char[][]strs=new char[4][5];
//录入用户输入的诗
for(int i=0;i<strs.length;i++){
System.out.print("请输入第"+(i+1)+"句诗");
String str=input.nextLine();
for(int j=0;j<strs[i].length;j++){
strs[i][j]=str.charAt(j);
}
}
//输出用户录入的诗
for (int i = 0; i < strs[0].length; i++) {
for (int j = 0; j < strs.length; j++) {
System.out.print(strs[j][i] + " ");
}
System.out.println();
}
}
}
以上是关于DELPHI二维数组设置长度的时候出现了难以理解的问题!急求高人指教!的主要内容,如果未能解决你的问题,请参考以下文章