数组

Delphi多维数组Copy有问题!

由 非洲饿鱼 于 星期日, 07/17/2011 - 20:11 发表

看http://qc.embarcadero.com/wc/qcmain.aspx?d=20086
fpc编译结果一样!

type
  TVector = array of integer;
  TMatrix = array of array of integer;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  A, B : TMatrix;
  C, D : TVector;
begin
  SetLength(C, 2);
  C[0] := 1;
  //this duplicates the vector
  D := Copy(C);
  D[0] := 2;
  //correctly shows "1"
  ShowMessage(IntToStr(C[0]));
  SetLength(A, 2, 2);
  A[0,0] := 1;
  //this should duplicate the matrix
  B := Copy(A);
  B[0,0] := 2;
  //oops: it shows "2"
  ShowMessage(IntToStr(A[0,0]));
end;

同步内容
Drupal theme by Kiwi Themes.