此过程一般情况下不出问题,但有时在处出问题!
出问题概率20%
procedure TF_pdb.stringgrid_changeClick(Sender: TObject);
var i,j:integer;
beginStringGridPrint.ColCount:=dbgrid1.FieldCount+1;
StringGridPrint.RowCount :=DBGrid1.DataSource.DataSet.RecordCount+1;
StringGridPrint.Cells[0,0]:='打印数量';
  for i:=1 to  dbgrid1.FieldCount do
    begin
****   StringGridPrint.Cells[i,0]:=dbgrid1.Fields[i-1].DisplayName ;
    end;
    table1.First;
  for i:=0 to Table1.RecordCount-1  do
  begin
    for j:=0 to dbgrid1.FieldCount-1 do
      begin
****      If Not dbgrid1.Fields[j].IsNull then  StringGridPrint.Cells[(j+1),(i+1)]:=dbgrid1.Fields[j].AsString
        Else  StringGridPrint.Cells[(j+1),(i+1)]:='';
      end;
    table1.Next ;
  end;
  
  
end;

解决方案 »

  1.   

    StringGridPrint.Cells[i,0]:=dbgrid1.Fields[i-1].DisplayName ;报过错
    在If Not dbgrid1.Fields[j].IsNull then  StringGridPrint.Cells[(j+1),(i+1)]:=dbgrid1.Fields[j].AsString
            Else  StringGridPrint.Cells[(j+1),(i+1)]:='';
          也报过错,
    但报错概率为20%,一般情况不报错!
    (此过程在程序中被多次执行。第一次执行没报过错第二次以后开始有报错!)
        
      

  2.   

    要看具体什么错误了,建议你用断点加上watches窗口仔细调一下