其他分享
首页 > 其他分享> > 多维数组 && 动态多维数组

多维数组 && 动态多维数组

作者:互联网

多维数组:

procedure TForm1.Button1Click(Sender: TObject);
const
  arr1:array[0..1,0..2,0..3]of Integer =(((1,2,3,4),(1,2,3,4),(1,2,3,4)),((1,2,3,4),(1,2,3,4),(1,2,3,4)));
begin
ShowMessage(IntToStr(SizeOf(arr1)div SizeOf(Integer)));//96/4=24 利用SizeOf快速得出多維數組的元素個數。
end;

动态多维数组赋值:

procedure TForm1.Button4Click(Sender: TObject);
var
  myarray:array of array of array of string;
  i,m,k,count:Integer;
  str:string;
begin
  count :=0;
  Memo1.Clear;
  SetLength(myarray,2);
  for i:=Low(myarray)to High(myarray)do
  begin
    SetLength (myarray[i],3);
  end;
  for i:=Low(myarray) to High(myarray) do
  begin
    for m:=Low(myarray[i])to High(myarray[i])do
    begin
      //for k:=Low(myarray[i,m])to High(myarray[i,m])do
      SetLength(myarray[i,m],4);
    end;
  end;
  for i:=Low(myarray)to High(myarray)do
  begin
    for m:=Low(myarray[i]) to High(myarray[i]) do
    begin
      for k:=Low(myarray[i,m]) to High(myarray[i,m]) do
      begin
        inc(count);
        str:='';
        myarray[i,m,k]:='i:='+inttostr(i)+',m:='+inttostr(m)+',k:='+IntToStr(k);
        str:=str+'   '+ myarray[i,m,k];
        Delete(str,1,3);
        Memo1.Lines.Add(str);
      end;
    end;
  end;
  Memo1.Lines.Add(IntToStr(count));

end;

 

标签:do,begin,end,数组,myarray,High,Low,&&,多维
来源: https://www.cnblogs.com/168-h/p/15250622.html