发新话题
打印

我想请教如何给一个二维数组动态的赋值

我想请教如何给一个二维数组动态的赋值

我想请教如何给一个二维数组动态的赋值,用edit输入数组的维数,然后再用edit2输入数组的各个元素,用button点击输入,请大家帮忙了

TOP

参见下面文章
http://www.puiching.edu.hk/~wtchung/trace/CPP/cpp15_c.htm

TOP

看看下面的单元,是你要的动态数组的副职的:
unit Unit1;

interface

uses
  // The System unit does not need to be defined
  SysUtils,
  Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm} // Include form definitions

procedure TForm1.FormCreate(Sender: TObject);
var
  singleArray : array of string;
  multiArray  : array of array of Word;
  i, j : Integer;

begin
  // Set the length of a single dimension array
  SetLength(singleArray, 4);

  // Now fill it up : note that dynamic arrays start at 0
  ShowMessage('Single dimensional array :');
  for i := 0 to 3 do
  begin
    singleArray := 'String '+IntToStr(i);
    ShowMessage('Element '+IntToStr(i)+' = '+singleArray);
  end;

  // Set the length of a multi dimensional array
  SetLength(multiArray, 2, 3);

  // Now fill it up
  ShowMessage('Multi-dimensional array :');
  for i := 0 to 1 do
    for j := 0 to 2 do
    begin
      multiArray[i,j] := i + j;
      ShowMessage('Element '+IntToStr(i)+','+IntToStr(j)+' = '+
                  IntToStr(multiArray[i,j]));
    end;
end;

end.

TOP

版主果然比我强
换个头像,看见广告就眼红,直接封ID。

TOP

发新话题