请个位帮我看看,怎么回事

yuyangzyc 2002-01-17 09:08:39
在按钮的点击事件里
var maxid:integer;
begin
table1.insert;
with query1.create(nil) do
begin
try
close;
sql.add('select max(qt_id)+1 from qt');
open;
maxid:=fields[0].asinteger;
finally;
free;
dbedit5.text:=inttostr(maxid);
end;
end;
end;
这个当第一次执行的时候可以通过而且在DBEDIT5返回了最大值+1(注,其他记录没有添加),但是如果我想取消这次操作时,在点击另一个按扭的时候(这个按扭的作用是table.cancel)或者关闭这个窗体,然后在执行这个事件得时候,程序报错,内容市这样的
access ciolotion at address 00437e58 in module 'project2.exe' read of address FFFFFFF.
不知道我说的是否详细,请告诉我这是怎么回事,好吗,谢谢!!!!
...全文
117 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyangzyc 2002-01-17
  • 打赏
  • 举报
回复
怎么样可以,把他提交倒数拒库中(远程的库)
CeleronII 2002-01-17
  • 打赏
  • 举报
回复
应该是with TQuery.Create(Application) do
然后还要指定DATABASENAME啊。
王集鹄 2002-01-17
  • 打赏
  • 举报
回复
No.1
procedure TForm1.Button1Click(Sender: TObject);
var
MaxId: Integer;
begin
Table1.Insert;

MaxId := -1;
with TQuery.Create(nil) do try
DatabaseName := Tabel1.DatabaseName;
SQL.Text := 'select max(qt_id)+1 from qt';
Open;
MaxId := Fields[0].AsInteger;
finally
Free;
end;

DBEdit5.Filed.DataSet.Edit;
DBEdit5.Filed.AsInteger := MaxId;
end;
王集鹄 2002-01-17
  • 打赏
  • 举报
回复
No.2
var
MaxId: Integer;
begin
Table1.Insert;
with Query1 do try
Close;
SQL.Text := 'select max(qt_id)+1 from qt';
Open;
MaxId := Fields[0].AsInteger;
except
MaxId := -1;
end;
DBEdit5.Filed.DataSet.Edit;
DBEdit5.Filed.AsInteger := MaxId;
end;
Mozh 2002-01-17
  • 打赏
  • 举报
回复
在 close 之后少了一句:
sql.clear;
你第二次执行的时候, SQL已变成
select max(qt_id)+1 from qt select max(qt_id)+1 from qt
你说有没有错?????
王集鹄 2002-01-17
  • 打赏
  • 举报
回复
No.1
with TQuery.Create(nil) do try
// DatabaseName := ?;
finally
Free;
end;

No.2
with Query1 do try
// Close;
except

end;
zengyufeng 2002-01-17
  • 打赏
  • 举报
回复
跟Owner无关,你的Query的Database怎么没有给出?
yxjjx 2002-01-17
  • 打赏
  • 举报
回复
with query1.create(nil) do把这句改成
with tquery1.create(self) do
gzmhero 2002-01-17
  • 打赏
  • 举报
回复
你的query1是什么啊,是否应该改成
query1:=TQuery.Create(Owner);

with query1 do
begin
.....
end;

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧