我想让stringgrid显示一个2唯数组的信息
主要有以下几点问题
1、stringgrid的行和列与该2唯数组的行列始终保持一致
2、当该2唯数组中的数据发生变化时stringgrid会即时刷新,即重画。
请问这两点该如何实现?

解决方案 »

  1.   

    var
      MyArr: array of array of string;
      I, J, RowCount, ColCount: Integer;
    begin
      Randomize;
      RowCount := Random(30);
      ColCount := Random(40);
      StringGrid1.FixedCols := 0;
      StringGrid1.FixedRows := 0;
      StringGrid1.RowCount := RowCount;
      StringGrid1.ColCount := ColCount;
      SetLength(MyArr, RowCount, ColCount);
      for I := 0 to RowCount - 1 do
        for J := 0 to ColCount - 1 do
        begin
          MyArr[I, J] := '[' + IntToStr(I) + ',' + IntToStr(J) + ']';
          StringGrid1.Cells[J, I] := MyArr[I, J];
        end;
    end;
      

  2.   

    楼上兄台,你的代码非常清楚,明白
    可能我说的可能不太明白,我是想把对数组的操作和对stringgrid的操作分开执行
    比方说一个函数改变了数组中的部分数值,那么stringgrid只要发现数组发生变化,就随之发生变化。
      

  3.   

    var
      MyArr: array of array of string;
      I, J, RowCount, ColCount: Integer;
    begin
      Randomize;
      RowCount := Random(30);
      ColCount := Random(40);
      StringGrid1.FixedCols := 0;
      StringGrid1.FixedRows := 0;
      StringGrid1.RowCount := RowCount;
      StringGrid1.ColCount := ColCount;
      SetLength(MyArr, RowCount, ColCount);
      for I := 0 to RowCount - 1 do
        for J := 0 to ColCount - 1 do
          MyArr[I, J] := '[' + IntToStr(I) + ',' + IntToStr(J) + ']';  for I := 0 to RowCount - 1 do
        for J := 0 to ColCount - 1 do
          StringGrid1.Cells[J, I] := MyArr[I, J];
    end;把MyArr的赋值和对StringGrid的操作分开就行了。
    在一个地方判断MyArr有变动了,那就执行StringGrid的更新。
      

  4.   

    jacky_shen
    非常感谢你的帮助
    我已经解决了我原来的问题,不过不是用你的方法
    我想问一下在你给我贴的代码中有一句是这样的
    MyArr: array of array of string;
    是不是声明了一个动态的数组?SetLength(MyArr, RowCount, ColCount);
    是不是定义了数组的行数和列数?如果我有一个函数它的参数为一个数组,
    而我在程序运行前不知道该数组的行数和列数
    那么我该怎么实现这个数组参数的传递呢?比方说我的函数是这样的
    procedure myfounction(myarray:array of....)
                          ~~~~~~~~~~~~~~~~~~~~~
    参数部分该怎么声明呢?
    我想在调用该函数的时候,此数组参数的行数和列数是程序运行时动态变化的!