报表查询出现错误  提示list   index   out   of   bounds(1)代码如下
procedure Tfrmstress_Day.FormCreate(Sender: TObject);
var
  i:Integer;
begin
  DTPMonth.Date := Now;                       // 显示当前日期  for i := 0 to StrobeCount-1 do
  begin
    cmbStrobeName.Items.Add(StrobeName[i]); // 添加闸站名称
  end;  cmbStrobeName.ItemIndex := 0;               // 显示第一条
end;procedure Tfrmstress_Day.RzBtnQueryClick(Sender: TObject);
var
  i:Integer;
  Year,Month,Day:Word;
begin
  DecodeDate(DTPMonth.Date,Year,Month,Day);  i := cmbStrobeName.ItemIndex;           // 获取索引  DBChart.Title.Caption := '应力变化涂图';
  DBChart.SubTitle.Caption := InttoStr(Year) + '年' + InttoStr(Month) + '月';  with adostress do
  begin
    Close;
    Sql.Clear;
    Sql.Text := 'Select * From bs_stress_Day Where STCD=' + QuotedStr(STCD[i]) +
              ' and Year(Systime)=' + InttoStr(Year) + 
              ' and Month(Systime)=' + InttoStr(Month) + 
              ' and stress is not Null';
    Open;
  end;
  StatusBar1.Panels[0].Text := ' 共查询到 ' + InttoStr(adostress.RecordCount) + ' 条数据!';
end;procedure Tfrmstress_Day.RzBtnStatClick(Sender: TObject);
var
  i:Integer;
  Year,Month,Day:Word;
begin
  DecodeDate(DTPMonth.Date,Year,Month,Day);  i := cmbStrobeName.ItemIndex;  try
    with adoSP do
    begin
      Parameters[1].Value := STCD[i];                    // 闸站编号
      Parameters[2].Value := Year;                           // 年
      Parameters[3].Value := Month;                          // 月
      ExecProc;
    end;
    Application.MessageBox('统计完毕!','提示',MB_OK + MB_ICONINFORMATION);
  finally
    RzBtnQuery.Click;
  end;
end;

解决方案 »

  1.   

    检查StrobeCount这个值是不是小于1
      

  2.   

     i := cmbStrobeName.ItemIndex;          // 获取索引 
    超出了界限吧。
    错误的意思就是列表的上下界出了问题
      

  3.   

    越界,根据你的代码看可能有两种原因:
    1、for i := 0 to StrobeCount-1 do  当 StrobeCount<1情况
    2、  i := cmbStrobeName.ItemIndex;   try 
        with adoSP do 
        begin 
          Parameters[1].Value := STCD[i];                    // 闸站编号 
    当cmbStrobeName.ItemIndex = -1情况
      

  4.   

    哪句报错就在哪句设断点,观察一下TList里Index的值
      

  5.   

    越界,根据你的代码看可能有两种原因: 
    1、for i := 0 to StrobeCount-1 do  当 StrobeCount <1情况 
    2、  i := cmbStrobeName.ItemIndex;   try 
        with adoSP do 
        begin 
          Parameters[1].Value := STCD[i];                    // 闸站编号 
    当cmbStrobeName.ItemIndex = -1情况哪句报错就在哪句设断点,观察一下TList里Index的值
      

  6.   

    越界了。
    唉来晚了。Parameters[1].Value := STCD[i];                    // 闸站编号 就是这个i了