我动态创建控件时出错,
请高手指教
代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,jmax,imax:Integer;
qrlabels:array of array of TLabel;
begin
  jmax:=7;
  imax:=10;
  SetLength(qrlabels,imax,jmax);
  for i:=0 to imax do
    for j:=0 to jmax do
        begin
            qrlabels[i,j]:=TLabel.Create(Self);
            qrlabels[i,j].Parent:=Self;
            qrlabels[i,j].Width:=20;
            qrlabels[i,j].Left:=i*21;
            qrlabels[i,j].Height:=20;
            qrlabels[i,j].Top:=j*21;
        end;
end;

解决方案 »

  1.   

    需要给每个Table命名,
    在创建后面加上这句试试
    qrlabels[i,j].name := 'qrlabel' + inttostr(i)+ inttostr(j);
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    i,j,jmax,imax:Integer;
    qrlabels:array of array of TLabel;
    begin
      jmax:=7;
      imax:=10;
      SetLength(qrlabels,imax,jmax);
      for i:=0 to imax -1 do
        for j:=0 to jmax - 1 do
            begin
                qrlabels[i,j]:=TLabel.Create(Self);
                qrlabels[i,j].Parent:=Self;
                qrlabels[i,j].Width:=20;
                qrlabels[i,j].Left:=i*21;
                qrlabels[i,j].Height:=20;
                qrlabels[i,j].Top:=j*21;
            end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    i,j,jmax,imax:Integer;
    qrlabels:array of array of TLabel;
    begin
      jmax:=7;
      imax:=10;
      SetLength(qrlabels,imax);
      for i:=0 to imax-1 do
      begin
        SetLength(qrlabels[i],jmax); 
        for j:=0 to jmax-1 do
            begin
                qrlabels[i,j]:=TLabel.Create(Self);
                qrlabels[i,j].Parent:=Self;
                qrlabels[i,j].Width:=20;
                qrlabels[i,j].Left:=i*21;
                qrlabels[i,j].Height:=20;
                qrlabels[i,j].Top:=j*21;
            end;
      end;
    end;
      

  4.   

    SetLength(qrlabels,imax,jmax);有问题
    需要改为
    SetLength(qrlabels,imax+1,jmax+1);
    因为你的循环是从0开始的