查看完整版本: 我想请教如何给一个二维数组动态的赋值

mxd6815742 2005-2-23 08:58

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

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

Nothing 2005-2-23 09:41

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

网事如风 2005-3-10 12:07

看看下面的单元,是你要的动态数组的副职的:
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[i] := 'String '+IntToStr(i);
    ShowMessage('Element '+IntToStr(i)+' = '+singleArray[i]);
  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.

Nothing 2005-3-10 21:54

版主果然比我强
页: [1]
查看完整版本: 我想请教如何给一个二维数组动态的赋值