Z
zhangktkt
Unregistered / Unconfirmed
GUEST, unregistred user!
求各位高手帮忙,我在做一个管理软件,有个功能是用图表曲线显示销售量
程序中的部分代码如下:
procedure TFrmLookupXsmx.RzBitBtn2Click(Sender: TObject);
begin
if FrmxsChart=nil then
frmxsChart := TFrmxsChart.Create(self);
try
Frmxschart.ShowModal;
except
on e:exception do
frmxsChart.free;
end; // 点击按钮后显示曲线图
曲线图窗体formshow事件如下:
procedure TFrmxsChart.FormShow(Sender: TObject);
var
sqlcmd:string;
begin
FrmxsChart.Series1.Active := False;
FrmxsChart.Series1.XLabelsSource := '';
FrmxsChart.Series1.YValues.ValueSource := '';
dbchart1.Title.Text.Clear;
dbchart1.Title.Text.Append('销售量曲线图');
with MaindataModual do
begin
qrytmp1.Close;
qrytmp1.SQL.Clear;
qrykh.close;
qrykh.SQL.Clear;
qrykh.SQL.Add('select * from sysobjects where xtype=''u'' and name=''tmp''');
qrykh.Open;
if qrykh.RecordCount>0 then
begin
qrykh.close;
qrykh.SQL.Clear;
qrykh.SQL.Add('drop table tmp');
qrykh.ExecSQL;
end;
qrykh.Close;
qrykh.SQL.Clear;
qrykh.SQL.add('select xlh,sr_rq,zl into tmp from v_xsmx where xlh is not null');
if trim(FrmLookupXsmx.dbcbkhmc.Text) <> '全部' then
begin
qrykh.SQL.add(' and khmc like :khmc');
qrykh.Parameters.ParamByName('khmc').Value :=trim(FrmLookupXsmx.dbcbkhmc.Text);
end ;
if trim(FrmLookupXsmx.dbcbtdbh.Text) <> '全部' then
begin
qrykh.SQL.add(' and tdbh like :tdbh');
qrykh.Parameters.ParamByName('tdbh').Value :=trim(FrmLookupXsmx.dbcbtdbh.Text);
end;
if trim(FrmLookupXsmx.dbcbck.Text) <> '全部' then
begin
qrykh.SQL.add(' and ckmc like :ckmc');
qrykh.Parameters.ParamByName('ckmc').Value :=trim(FrmLookupXsmx.dbcbck.Text);
end;
if (trim(FrmLookupXsmx.dbcbxh.Text)<>'全部') and (trim(FrmLookupXsmx.dbcbxh.text)<>'')then
begin
qrykh.SQL.Add(' and xh like :xh');
qrykh.Parameters.ParamByName('xh').Value := trim(FrmLookupXsmx.dbcbxh.Text);
end;
if (trim(FrmLookupXsmx.dbcbgg.Text)<>'全部') and (trim(FrmLookupXsmx.dbcbgg.text)<>'')then
begin
qrykh.SQL.Add(' and gg like :gg');
qrykh.Parameters.ParamByName('gg').Value := trim(FrmLookupXsmx.dbcbgg.Text);
end;
qrykh.SQL.Add(' and sr_rq >=' + QuotedStr(DateTimeToStr(FrmLookupXsmx.dtedtB.Date)));
qrykh.SQL.Add(' and sr_rq <=' + QuotedStr(DateTimeToStr(FrmLookupXsmx.dtedtE.Date)));
qrykh.SQL.Add('and tdbh in (select tdbh from Kc_jb_thd where bj=''n'')') ;
qrykh.Prepared;
qrykh.ExecSQL;
qrytmp1.SQL.Append('select sr_rq,sum(zl) as zzl from tmp group by sr_rq');
qrytmp1.Open;
if qrytmp1.RecordCount=0 then
showmessage('限定数据为空');
end;
series1.DataSource := MaindataModual.qrytmp1;
series1.XLabelsSource:= 'sr_rq';
series1.XValues.ValueSource := 'sr_rq';
series1.XValues.DateTime := true;
series1.YValues.ValueSource:='zzl';
series1.YValues.DateTime := false;
series1.Active := true;
end;
当程序执行时,如果sql查询那段代码的限定条件都是全部是一切正常
但如果我FrmLookupXsmx.dbcbkhmc.Text不为全部时(如:森节塑胶机械厂 , 有时赋其他的值则正常),就会在在formshow时间执行结束后弹出错误提示 access volation 。不知道是什么原因,就高手指点下,我是新手
程序中的部分代码如下:
procedure TFrmLookupXsmx.RzBitBtn2Click(Sender: TObject);
begin
if FrmxsChart=nil then
frmxsChart := TFrmxsChart.Create(self);
try
Frmxschart.ShowModal;
except
on e:exception do
frmxsChart.free;
end; // 点击按钮后显示曲线图
曲线图窗体formshow事件如下:
procedure TFrmxsChart.FormShow(Sender: TObject);
var
sqlcmd:string;
begin
FrmxsChart.Series1.Active := False;
FrmxsChart.Series1.XLabelsSource := '';
FrmxsChart.Series1.YValues.ValueSource := '';
dbchart1.Title.Text.Clear;
dbchart1.Title.Text.Append('销售量曲线图');
with MaindataModual do
begin
qrytmp1.Close;
qrytmp1.SQL.Clear;
qrykh.close;
qrykh.SQL.Clear;
qrykh.SQL.Add('select * from sysobjects where xtype=''u'' and name=''tmp''');
qrykh.Open;
if qrykh.RecordCount>0 then
begin
qrykh.close;
qrykh.SQL.Clear;
qrykh.SQL.Add('drop table tmp');
qrykh.ExecSQL;
end;
qrykh.Close;
qrykh.SQL.Clear;
qrykh.SQL.add('select xlh,sr_rq,zl into tmp from v_xsmx where xlh is not null');
if trim(FrmLookupXsmx.dbcbkhmc.Text) <> '全部' then
begin
qrykh.SQL.add(' and khmc like :khmc');
qrykh.Parameters.ParamByName('khmc').Value :=trim(FrmLookupXsmx.dbcbkhmc.Text);
end ;
if trim(FrmLookupXsmx.dbcbtdbh.Text) <> '全部' then
begin
qrykh.SQL.add(' and tdbh like :tdbh');
qrykh.Parameters.ParamByName('tdbh').Value :=trim(FrmLookupXsmx.dbcbtdbh.Text);
end;
if trim(FrmLookupXsmx.dbcbck.Text) <> '全部' then
begin
qrykh.SQL.add(' and ckmc like :ckmc');
qrykh.Parameters.ParamByName('ckmc').Value :=trim(FrmLookupXsmx.dbcbck.Text);
end;
if (trim(FrmLookupXsmx.dbcbxh.Text)<>'全部') and (trim(FrmLookupXsmx.dbcbxh.text)<>'')then
begin
qrykh.SQL.Add(' and xh like :xh');
qrykh.Parameters.ParamByName('xh').Value := trim(FrmLookupXsmx.dbcbxh.Text);
end;
if (trim(FrmLookupXsmx.dbcbgg.Text)<>'全部') and (trim(FrmLookupXsmx.dbcbgg.text)<>'')then
begin
qrykh.SQL.Add(' and gg like :gg');
qrykh.Parameters.ParamByName('gg').Value := trim(FrmLookupXsmx.dbcbgg.Text);
end;
qrykh.SQL.Add(' and sr_rq >=' + QuotedStr(DateTimeToStr(FrmLookupXsmx.dtedtB.Date)));
qrykh.SQL.Add(' and sr_rq <=' + QuotedStr(DateTimeToStr(FrmLookupXsmx.dtedtE.Date)));
qrykh.SQL.Add('and tdbh in (select tdbh from Kc_jb_thd where bj=''n'')') ;
qrykh.Prepared;
qrykh.ExecSQL;
qrytmp1.SQL.Append('select sr_rq,sum(zl) as zzl from tmp group by sr_rq');
qrytmp1.Open;
if qrytmp1.RecordCount=0 then
showmessage('限定数据为空');
end;
series1.DataSource := MaindataModual.qrytmp1;
series1.XLabelsSource:= 'sr_rq';
series1.XValues.ValueSource := 'sr_rq';
series1.XValues.DateTime := true;
series1.YValues.ValueSource:='zzl';
series1.YValues.DateTime := false;
series1.Active := true;
end;
当程序执行时,如果sql查询那段代码的限定条件都是全部是一切正常
但如果我FrmLookupXsmx.dbcbkhmc.Text不为全部时(如:森节塑胶机械厂 , 有时赋其他的值则正常),就会在在formshow时间执行结束后弹出错误提示 access volation 。不知道是什么原因,就高手指点下,我是新手