现在遇到一个很奇怪的问题,我的DBCHART上的N个Series,指定了他们的DATASOURCE属性为adotable1,程序第一次执行DBCHART上图画都出来的,第二次执行的时候当我执行ADOTABLE1.active:=true;的时候就出错了.提示"access violation at address 304cf114"
程序代码如下,第一次执行成功的,第二次执行在adotable1打开时出错,怀疑是
dbchart3.SeriesList.Destroy;这句话没有把series删除干净
procedure Txs_xsfx.btnqsfxClick(Sender: TObject);
var
sjly,sqlstr,fxfw:string;
i,j:integer;
aaa:array of tfastlineseries;
begin
if cbfxkssj.Date>cbfxjssj.Date then
  begin
    showmessage('趋势分析的开始时间不能大于趋势分析的结束时间!');
    exit;
  end;
adotable1.Active:=false;
adotable1.TableName:='';
if dbchart3.SeriesCount>0 then
   dbchart3.SeriesList.Destroy;
if ckdd.Checked then
   sjly:='0';
if cksh.Checked then
   sjly:='1';
if ckkp.Checked then
   sjly:='2';
if ckywy.Checked then
   fxfw:='1';
if ckkh.Checked then
   fxfw:='0';
if ckdq.Checked then
   fxfw:='2';
if ckhy.Checked then
   fxfw:='3';
dbgrid1.Visible:=false;
dbgrid2.Visible:=true;
with query2 do
  begin
    close;
    sql.Clear;
    sql.Add('exec xs_qsfx ''##qsfx'+userid+''','''+datetostr(cbfxkssj.Date)+''','''+datetostr(cbfxjssj.Date)+''','''+fxfw+''','''+sjly+'''');
    execsql;
    close;
    sql.Clear;
    sql.Add('select top 10 * from ##qsfx'+userid+'');
    open;
  end;
j:=query2.FieldCount-1;
with query4 do
  begin
    close;
    sql.Clear;
    sqlstr:='select top 10 fxfw,';
    for i:=1 to j do
      begin
        sqlstr:=sqlstr+'sum('+query2.Fields[i].FieldName+'),';
        query2.Next;
      end;
    sqlstr:=copy(sqlstr,1,length(sqlstr)-1)+' from ##qsfx'+userid+' group by fxfw';
    sql.Add(sqlstr);
    open;
  end;
j:=query4.RecordCount;
with query3 do
  begin
    close;
    sql.Clear;
    sql.Add('if object_id ( ''tempdb..##qsfxtemp'+userid+''') is not null drop table ##qsfxtemp'+userid+'');
    sql.Add(' create table ##qsfxtemp'+userid+' (');
    sql.Add('周期 int not null,');
    for i:=1 to j do
      begin
        sql.Add(''+query4.Fields[0].AsString+' decimal(9, 2) NULL,');
        query4.Next;
      end;
    sql.Text:=copy(sql.Text,1,length(sql.Text)-1)+')';
    execsql;
  end;
adotable1.TableName:='##qsfxtemp'+userid;
adotable1.Active:=true;  ///这里出错了with query4 do
    for i:=1 to query4.FieldCount-1 do
      begin
        First;
        adotable1.Insert;
        adotable1.Fields[0].AsInteger:=i;
        for j:=1 to query4.RecordCount do
          begin
            adotable1.Fields[j].AsFloat:=query4.Fields[i].AsFloat;
            query4.Next;
          end;
      end;
adotable1.Post;
setlength(aaa,adotable1.FieldCount-1);
for i:=0 to adotable1.FieldCount-2  do
  begin
   aaa[i]:=tfastlineseries.Create(self);
   dbchart3.AddSeries(aaa[i]);
   aaa[i].DataSource:=adotable1;
   aaa[i].XValues.ValueSource:='周期';
   aaa[i].YValues.ValueSource:=adotable1.Fields[i+1].FieldName;
   aaa[i].XLabelsSource:='周期';
   aaa[i].Title:=adotable1.Fields[i+1].FieldName;
  end;
end;