运行一个组件出错,这是为什么?高手指点下我要怎么改? Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiDB/html/delphi_20061219211358215.html
我用delphi和sql sever做了一个试卷生成系统,用的BDE连接的,按F9运行都没问题,出现登陆界面后能正常登陆,但点试卷管理中的定制试卷就出现错误提示,但关闭这个提示就能出现后面的界面,我第二次点定制试卷就不会报这个错误
project project1.exe raised exception class EDatabase Error with message
Table_shijuan:cannot perform this operation on a close dataset process stopped use step or run to continue.
如果我直接运行project1.exe ,再点定制试卷,就会出这个提示
Table_shijuan cannot perform this operation on a close dataset
这个是unit10也就是定制试卷窗口的代码,会提示第四行newshijuanhao:=DataModule4.Table_shijuan.FieldValues['jno']+1;
出错,高手帮我看看
procedure Tdefinepaperform.FormShow(Sender: TObject);
begin
DataModule4.Table_shijuan.Last;
newshijuanhao:=DataModule4.Table_shijuan.FieldValues['jno']+1;
DataModule4.Table_shijuan.First;
end;
procedure Tdefinepaperform.BitBtn1Click(Sender: TObject);
begin
if addshijuan then
begin
if checknewshijuan then
begin
DataModule4.Table_shijuan.Post;
DataModule4.Table_shijuan.Close;
DataModule4.Table_shijuan.Open;
showmessage('新试卷添加成功!');
addshijuan:=false;
inc(newshijuanhao);
// DataModule4.Table_shijuan.UpdateRecord;
DBNavigator1.CanFocus;
BitBtn3.Enabled:=true;
BitBtn4.Enabled:=true;
end
else
exit;
end;
end;
procedure Tdefinepaperform.DBEdit6Change(Sender: TObject);
begin
sum1:=0;
if (DBEdit3.Text<>'')and(DBEdit6.Text<>'') then
begin
sum1:=sum1+strtoint(DBEdit3.Text)*strtoint(DBEdit6.Text);
DBEdit9.Text:=inttostr(sum1);
end;
end;
procedure Tdefinepaperform.DBEdit7Change(Sender: TObject);
begin
sum2:=0;
if (DBEdit4.Text<>'')and(DBEdit7.Text<>'') then
begin
sum2:=sum2+strtoint(DBEdit4.Text)*strtoint(DBEdit7.Text);
DBEdit10.Text:=inttostr(sum2);
end;
end;
procedure Tdefinepaperform.DBEdit8Change(Sender: TObject);
begin
sum3:=0;
if (DBEdit5.Text<>'')and(DBEdit8.Text<>'') then
begin
sum3:=sum3+strtoint(DBEdit5.Text)*strtoint(DBEdit8.Text);
DBEdit11.Text:=inttostr(sum3);
end;
end;
procedure Tdefinepaperform.DBEdit13Change(Sender: TObject);
begin
sum4:=0;
if (DBEdit12.Text<>'')and(DBEdit13.Text<>'') then
begin
sum4:=sum4+strtoint(DBEdit12.Text)*strtoint(DBEdit13.Text);
DBEdit14.Text:=inttostr(sum4);
end;
end;
procedure Tdefinepaperform.DBEdit16Change(Sender: TObject);
begin
sum5:=0;
if (DBEdit15.Text<>'')and(DBEdit16.Text<>'') then
begin
sum5:=sum5+strtoint(DBEdit15.Text)*strtoint(DBEdit16.Text);
DBEdit17.Text:=inttostr(sum5);
end;
end;
procedure Tdefinepaperform.DBEdit17Change(Sender: TObject);
begin
allsum:=0;
if (DBEdit9.Text<>'')and(DBEdit10.Text<>'')and(DBEdit11.Text<>'')and(DBEdit14.Text<>'')and(DBEdit17.Text<>'') then
begin
allsum:=allsum+sum1+sum2+sum3+sum4+sum5;
DBEdit2.Text:=inttostr(allsum);
end;
end;
procedure Tdefinepaperform.DBEdit14Change(Sender: TObject);
begin
allsum:=0;
if (DBEdit9.Text<>'')and(DBEdit10.Text<>'')and(DBEdit11.Text<>'')and(DBEdit14.Text<>'')and(DBEdit17.Text<>'') then
begin
allsum:=allsum+sum1+sum2+sum3+sum4+sum5;
DBEdit2.Text:=inttostr(allsum);
end;
end;
procedure Tdefinepaperform.DBEdit11Change(Sender: TObject);
begin
allsum:=0;
if (DBEdit9.Text<>'')and(DBEdit10.Text<>'')and(DBEdit11.Text<>'')and(DBEdit14.Text<>'')and(DBEdit17.Text<>'') then
begin
allsum:=allsum+sum1+sum2+sum3+sum4+sum5;
DBEdit2.Text:=inttostr(allsum);
end;
end;
procedure Tdefinepaperform.DBEdit10Change(Sender: TObject);
begin
allsum:=0;
if (DBEdit9.Text<>'')and(DBEdit10.Text<>'')and(DBEdit11.Text<>'')and(DBEdit14.Text<>'')and(DBEdit17.Text<>'') then
begin
allsum:=allsum+sum1+sum2+sum3+sum4+sum5;
DBEdit2.Text:=inttostr(allsum);
end;
end;
procedure Tdefinepaperform.DBEdit9Change(Sender: TObject);
begin
allsum:=0;
if (DBEdit9.Text<>'')and(DBEdit10.Text<>'')and(DBEdit11.Text<>'')and(DBEdit14.Text<>'')and(DBEdit17.Text<>'') then
begin
allsum:=allsum+sum1+sum2+sum3+sum4+sum5;
DBEdit2.Text:=inttostr(allsum);
end;
end;
procedure Tdefinepaperform.DBEdit3Change(Sender: TObject);
begin
sum1:=0;
if (DBEdit3.Text<>'')and(DBEdit6.Text<>'') then
begin
sum1:=sum1+strtoint(DBEdit3.Text)*strtoint(DBEdit6.Text);
DBEdit9.Text:=inttostr(sum1);
end;
end;
procedure Tdefinepaperform.DBEdit4Change(Sender: TObject);
begin
sum2:=0;
if (DBEdit4.Text<>'')and(DBEdit7.Text<>'') then
begin
sum2:=sum2+strtoint(DBEdit4.Text)*strtoint(DBEdit7.Text);
DBEdit10.Text:=inttostr(sum2);
end;
end;
procedure Tdefinepaperform.DBEdit5Change(Sender: TObject);
begin
sum3:=0;
if (DBEdit5.Text<>'')and(DBEdit8.Text<>'') then
begin
sum3:=sum3+strtoint(DBEdit5.Text)*strtoint(DBEdit8.Text);
DBEdit11.Text:=inttostr(sum3);
end;
end;
procedure Tdefinepaperform.DBEdit12Change(Sender: TObject);
begin
sum4:=0;
if (DBEdit12.Text<>'')and(DBEdit13.Text<>'') then
begin
sum4:=sum4+strtoint(DBEdit12.Text)*strtoint(DBEdit13.Text);
DBEdit14.Text:=inttostr(sum4);
end;
end;
procedure Tdefinepaperform.DBEdit15Change(Sender: TObject);
begin
sum5:=0;
if (DBEdit15.Text<>'')and(DBEdit16.Text<>'') then
begin
sum5:=sum5+strtoint(DBEdit15.Text)*strtoint(DBEdit16.Text);
DBEdit17.Text:=inttostr(sum5);
end;
end;
procedure Tdefinepaperform.BitBtn3Click(Sender: TObject);
var
i,j:integer;
begin
paperautoform.ProgressBar1.Position:=0;
for i:=1 to 800 do
begin
paperautoform.thao[i]:=0;
paperautoform.havetake[i]:=0;
end;
for j:=1 to 5 do
begin
paperautoform.diff[i]:=0;;
end;
paperautoform.Memo1.Text:='';
paperautoform.Show;
end;
procedure Tdefinepaperform.BitBtn2Click(Sender: TObject);
begin
DBNavigator1.BtnClick(nbCancel);
BitBtn3.Enabled:=true;
BitBtn4.Enabled:=true;
end;
好像是DataModule4.Table_shijuan没打开
unit Unit4;
interface
uses
SysUtils, Classes, DB, DBTables;
type
TDataModule4 = class(TDataModule)
Table_u: TTable;
DataSource_u: TDataSource;
DataSource_choose: TDataSource;
DataSource_filltext: TDataSource;
DataSource_judge: TDataSource;
DataSource_readpro: TDataSource;
Table_choose: TTable;
Table_filltext: TTable;
Table_judge: TTable;
Table_readpro: TTable;
DataSource_procedure: TDataSource;
Table_procedure: TTable;
Table_uID: TStringField;
Table_umi: TStringField;
Table_uqx: TStringField;
Table_choosetno: TIntegerField;
Table_choosetigan: TMemoField;
Table_choosexa: TStringField;
Table_choosexb: TStringField;
Table_choosexc: TStringField;
Table_choosexd: TStringField;
Table_chooseanswer: TStringField;
Table_choosescore: TSmallintField;
Table_choosedifficulty: TStringField;
Table_choosenote: TStringField;
DataSource_shijuan: TDataSource;
Table_shijuan: TTable;
Table_papermanager: TTable;
DataSource_papermanager: TDataSource;
Database1: TDatabase;
procedure Table_chooseBeforeDelete(DataSet: TDataSet);
procedure Table_chooseAfterDelete(DataSet: TDataSet);
procedure Table_filltextBeforeDelete(DataSet: TDataSet);
procedure Table_judgeBeforeDelete(DataSet: TDataSet);
procedure Table_readproBeforeDelete(DataSet: TDataSet);
procedure Table_procedureBeforeDelete(DataSet: TDataSet);
procedure Table_filltextAfterDelete(DataSet: TDataSet);
procedure Table_judgeAfterDelete(DataSet: TDataSet);
procedure Table_readproAfterDelete(DataSet: TDataSet);
procedure Table_procedureAfterDelete(DataSet: TDataSet);
procedure Table_shijuanBeforeDelete(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DataModule4: TDataModule4;
implementation
uses Unit3, Unit6, Unit7, Unit8, Unit9, Unit11, Unit10;
{$R *.dfm}
procedure TDataModule4.Table_chooseBeforeDelete(DataSet: TDataSet);
begin
mainform.updateno:=0;
mainform.updateno:=chooseform.Query1.FieldValues['tno'] ;
//exit;
//DBNavigator1.BtnClick(nbCancel);
//showmessage('请选择一个章节点') ;
//else
// mainform.updateno:=table_choose['tno'];
end;
procedure TDataModule4.Table_chooseAfterDelete(DataSet: TDataSet);
begin
DataModule4.Table_choose.Close;
DataModule4.Table_choose.Open;
DataModule4.Table_choose.Active:=false;
DataModule4.Table_choose.Active:=true;
end;
procedure TDataModule4.Table_filltextBeforeDelete(DataSet: TDataSet);
begin
mainform.updateno:=0;
mainform.updateno:=filltextform.Query1.FieldValues['tno'] ;
end;
procedure TDataModule4.Table_judgeBeforeDelete(DataSet: TDataSet);
begin
mainform.updateno:=0;
mainform.updateno:=judgeform.Query1.FieldValues['tno'] ;
end;
procedure TDataModule4.Table_readproBeforeDelete(DataSet: TDataSet);
begin
mainform.updateno:=0;
mainform.updateno:=readproform.Query1.FieldValues['tno'] ;
end;
procedure TDataModule4.Table_procedureBeforeDelete(DataSet: TDataSet);
begin
mainform.updateno:=0;
mainform.updateno:=procedureform.Query1.FieldValues['tno'] ;
end;
procedure TDataModule4.Table_filltextAfterDelete(DataSet: TDataSet);
begin
DataModule4.Table_filltext.Close;
DataModule4.Table_filltext.Open;
DataModule4.Table_filltext.Active:=false;
DataModule4.Table_filltext.Active:=true;
end;
procedure TDataModule4.Table_judgeAfterDelete(DataSet: TDataSet);
begin
DataModule4.Table_judge.Close;
DataModule4.Table_judge.Open;
DataModule4.Table_judge.Active:=false;
DataModule4.Table_judge.Active:=true;
end;
procedure TDataModule4.Table_readproAfterDelete(DataSet: TDataSet);
begin
DataModule4.Table_readpro.Close;
DataModule4.Table_readpro.Open;
DataModule4.Table_readpro.Active:=false;
DataModule4.Table_readpro.Active:=true;
end;
procedure TDataModule4.Table_procedureAfterDelete(DataSet: TDataSet);
begin
DataModule4.Table_procedure.Close;
DataModule4.Table_procedure.Open;
DataModule4.Table_procedure.Active:=false;
DataModule4.Table_procedure.Active:=true;
end;
procedure TDataModule4.Table_shijuanBeforeDelete(DataSet: TDataSet);
begin
definepaperform.updatejno:=0;
definepaperform.updatejno:=table_shijuan['jno'];
end;
end.
上面的是unit4的代码,麻烦高手看看
unit4是设置连接数据库的模块
DataModule4.Table_choose.Close; // 第一套
DataModule4.Table_choose.Open;
DataModule4.Table_choose.Active:=false; // 第二套
DataModule4.Table_choose.Active:=true;
类似这种代码用一套就行了。另一套删除
我删除了,没什么用,还是原来的问题
我删除了,没什么用,还是原来的问题
============================================================
我的意思是说有些是多余的语句,你的问题还是那个DataSet没打开进行了操作引起的。你把源码贴上来也不起多大作用,你可以进行调试跟踪,看错误发生在那条语句。
newshijuanhao:=DataModule4.Table_shijuan.FieldValues['jno']+1;
就是这一行出了错
unit10中的,要怎么修改?
我估计应该是这句的上一句就出错了。表没有打开。你可在DataModule4.Table_shijuan.Last;前面加一句DataModule4.Table_shijuan.Active := True;试一试,如果错误依然在这一句,说明错误在字段名或者字段类型上或者字段值为空。
高手,谢谢啊,问题解决了,就是少了这一句