1、获取 StringGrid 的行数、列数;
2、给单元赋值.
运行效果图:

//示例代码:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls, Grids;typeTForm1 = class(TForm)StringGrid1: TStringGrid;Panel1: TPanel;Button1: TButton;Button2: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}{显示列数与行数}
procedure TForm1.Button1Click(Sender: TObject);
varcCount,rCount: Integer;
begincCount := StringGrid1.ColCount; {获取总列数}rCount := StringGrid1.RowCount; {获取总行数}Text := Format('总列数: %d; 总行数: %d', [cCount, rCount]); {显示在标题}
end;{给每个单元赋值}
procedure TForm1.Button2Click(Sender: TObject);
varc,r: Integer;
beginfor c := 0 to StringGrid1.ColCount - 1 dofor r := 0 to StringGrid1.RowCount - 1 doStringGrid1.Cells[c,r] := Format('%d,%d', [c,r]);
end;end.