j: Variable 'j' inaccessible here due to optimization为什么呢?
还有
  i :=0;
  while (i < gCol) do
    begin
      arrX[i]         := TPanel.Create(Panel1);
      arrX[i].Parent  := Panel1;
      arrX[i].left    := edtShow.Width + (RoomW * i);
      arrX[i].Top     := 0;
      arrX[i].Width   := RoomW;
      arrX[i].Height  := RoomH;
      if (i < 9)
        then
          arrX[i].caption :='0' + IntToStr(i + 1)
        else
          arrX[i].Caption :=IntToStr(i + 1);
      i :=i + 1;
   end;其中的arrX[] 是TPanel数组为什么在arrX[i]的第一次计算时,arrX[0].left会等于零
而实际上应该出来edtShow.Width才对的。那为大哥帮我看看啊/

解决方案 »

  1.   

    procedure TfrmMain.Button1Click(Sender: TObject);
    var
      i, j :integer;
      arrX:array of TPanel;
    begin
      Panel1.SetBounds(0,120,700,400);
      Panel1.AutoSize :=false;
      if (Edit1.Text <> '')
        then
          gRow :=StrToInt(Edit1.Text)
        else  begin
          ShowMessage('楼层数不能为空');
          Edit1.SetFocus;
          halt;
        end;
      if (Edit2.Text <> '')
        then
          gCol :=StrToInt(Edit2.text)
        else begin
          ShowMessage('每层房间数不能为空');
          Edit2.SetFocus;
          halt;
        end;
      if ((Panel1.Width - 4 - RoomW) div gCol < 25)
        then
          RoomW :=25;
      if ((Panel1.Width - 4 - RoomW) div gCol >= 25) and ((Panel1.Width - 4 - RoomW) div gCol <= 50 )
        then
          RoomW :=((Panel1.Width - 4 - 27) div gCol) - 1;
      if ((Panel1.Width - 4 - RoomW) div gCol > 50)
        then
          RoomW :=50;
      if ((Panel1.Height - RoomH) div gRow < 25 )
        then
          RoomH :=25;
      if ((Panel1.Height - RoomH) div gRow >= 25 ) and  ((Panel1.Height - RoomH) div gRow <= 50 )
        then
          RoomH :=((Panel1.Height - 40) div gRow) - 1 ;
      if ((Panel1.Height - RoomH) div gRow > 50 )
        then
          RoomH :=50;
      if (RoomH < 40 )
        then
          edtShow.Width  :=40
        else
          edtShow.Width  :=RoomH;
      edtShow.Height :=RoomH;
      SetLength(arrZ,gRow,gCol);
      SetLength(arrY,gRow);
      Panel1.AutoSize :=true;
      for i := 0 to gRow - 1 do
        begin
          arrY[i].Flag :=false;
          for j := 0 to gCol - 1 do
            arrZ[i, j].Flag :=false;
        end;
      SetLength(arrX,gCol);
      i :=0;
      while (i < gCol) do
        begin
          arrX[i]         := TPanel.Create(Panel1);
          arrX[i].Parent  := Panel1;
          arrX[i].left    := edtShow.Width + (RoomW * i);
          arrX[i].Top     := 0;
          arrX[i].Width   := RoomW;
          arrX[i].Height  := RoomH;
          if (i < 9)
            then
              arrX[i].caption :='0' + IntToStr(i + 1)
            else
              arrX[i].Caption :=IntToStr(i + 1);
          i :=i + 1;
       end;
      i := 0;
      while (i < gRow) do
        begin
          arrY[i].Panel         := TPanel.Create(Panel1);
          arrY[i].Panel.Parent  := Panel1;
          arrY[i].Panel.left    := 0;
          arrY[i].Panel.Top     := (i + 1) * RoomH;
          arrY[i].Panel.Width   := edtShow.Width;
          arrY[i].Panel.Height  := RoomH;
          arrY[i].initTop       := (i + 1) * RoomH;
          arrY[i].CurTop        := (i + 1) * RoomH;
          if (i < 9)
            then
              arrY[i].Panel.caption :='0' + IntToStr(i + 1)
            else
              arrY[i].Panel.Caption :=IntToStr(i + 1);
          i :=i + 1;
        end;
      Notebook1.ActivePage :='2';
      gBottom :=RoomH * (gRow + 1);
    end;
    其中gRow是行数,
    gCol是列数.这两个都是全局变量
      

  2.   

    你把Panel1.AutoSize :=true;放到程序最后执行。