with ScoreStatisticsQuery do begin
    close;sql.Clear;
    sql.Add('select * from ScoreStatistics where SchoolName=:aa and EveryGrade=:bb and ScoreGroupName=:cc and kind=:dd');
    Parameters[0].Value:=SchoolName;
    Parameters[1].Value:=Grade;
    Parameters[2].Value:=ScoreGroup;
    Parameters[3].Value:=Kind;
    open;  for i:=1 to  ScoreStatisticsQuery.FieldCount-6 do
        StringGrid1.Cells[1,1]:=TempQuery.FieldList.Fields[5].AsString;  end;上面执行一个查询,用此句来写表格,但是在formcreate是无错,再调用时就显示index号出错。到底怎么回事?

解决方案 »

  1.   

    应该是数组溢出,“ScoreStatisticsQuery.FieldCount-6”或“TempQuery.FieldList.Fields[5].AsString”有错
    可能ScoreStatisticsQuery.FieldCount<6
    或TempQuery.FieldList.Fieldcount<5
      

  2.   

    但是在formcreate是无错,再调用时就显示index号出错。到底怎么回事?
      这有点奇怪.断点跟踪一下吧.本来我也是想如上楼那样回答.
      

  3.   

    见笑了,是我太粗心了:
    ScoreStatisticsQuery.FieldCount
     TempQuery.FieldList.Fields[5].AsString
    不能放在一起,我本意是
    ScoreStatisticsQuery.FieldCount
     ScoreStatisticsQuery.FieldList.Fields[5].AsString
    所以会出错,谢谢两位。