提交记录关键字重复时,我这样处理怎不行?(15分)

  • 主题发起人 主题发起人 okzjq
  • 开始时间 开始时间
O

okzjq

Unregistered / Unconfirmed
GUEST, unregistred user!
adoquery+access2000+dbNavigator

procedure TMTDepartmentForm.ADOQueryBeforePost(DataSet: TDataSet);
var
i:integer;
begin
inherited;
for i:=0 to adoQuery.fieldCount-2 do
begin
if adoquery.Fields.AsString='' then
begin
application.MessageBox('请先把信息填写完整!','',MB_OK+MB_IconInformation);
abort;
adoquery.Fields.FocusControl;
end;
end;
adoquery.First;
if adoQuery.Locate('XSH',dbtXSH.Text,[]) then
begin
showmessage('record repeat!');
abort;
end;

当记录关键字重复时系统显示:raised exception estackoverflow with message" stack
over flow"
请问怎样才能确保在关健字重复时显示自己提示信息,并且系统不会崩溃可能性呢?

我只有15而以,如果分数太少,还请体谅

 
63. Delphi中获得BDE、ADO的错误号
Delphi的数据库对象,如Ttable和TadoTable有以下一些Error事件:OnDeleteError、OnDeleteErro、OnPostError。这些事件的定义如下,都是数据集错误:
type TDataSetErrorEvent = procedure(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction) of object;
property OnPostError: TDataSetErrorEvent;

在这些事件在EdatabaseError中是无法得到错误号的,其中只有Message属性。在发生BDE错误时可如下得到错误号:
if E is EDBEngineError then
showmessage(inttostr(EDBEngineError(E).Errors[0].ErrorCode));
也可以这么写:
if E is EDBEngineError then
showmessage(inttostr((E As EDBEngineError).Errors[0].ErrorCode));
但在发生ADO错误时不能这样: E is EadoError。
其实Ado错误在数据集相应的数据库连接中都有:TadoConnection.Errors。
procedure TForm1.Table1PostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
var
i:integer;
begin
memo1.Lines.Add(inttostr(table1.Connection.errors.count ));
for i:=0 to AdoConnection1.errors.count-1 do
begin
memo1.Lines.Add('number:'+inttohex(AdoConnection1.errors.Number,8 ));
memo1.Lines.Add('NativeCode:'+inttostr(AdoConnection1.errors.NativeError ));
memo1.Lines.Add(inttostr(AdoConnection1.errors.HelpContext ));
memo1.Lines.Add(AdoConnection1.errors.Source );
memo1.Lines.Add(AdoConnection1.errors.SQLState );
memo1.Lines.Add('Description:'+AdoConnection1.errors.Description );
end;
memo1.Lines.Add('error Msg :'+e.message);
end;
NativeError是Foxpro的原生错误号,非常详细,一般用这个来判断发生的错误。Number是Sql错误号,是大的分类,一般一个Number和多个NativeError对应。
这些错误码的信息在文档Drvvfp.hlp中都有。

 
try
提交
except
....
showmessage('提交失败,可能是 record repeat!');
....
end;
 
try
提交
except
....
showmessage('提交失败,可能是 record repeat!');
raise;
....
end
 
楼上的朋友,我照你意思写了,还是出错啊!
procedure TMTDepartmentForm.tbtnPostClick(Sender: TObject);
begin
try
DBNavigator1.BtnClick(nbPost);
except
on EdatabaseError do
showmessage('错误信息');
end;
end;

我是用adoquery控件和Access2000数据库的
 

adoquery.First;
if adoQuery.Locate('XSH',dbtXSH.Text,[]) then
begin
showmessage('record repeat!');
abort;
end;

这点代码没有问题。
 
to 陈晨
可我运行时怎么老是出现:
  raised exception estackoverflow with message" stack over flow"
 请指点!!! 

 
(try ...)在Delphi中运行的吧,编译后脱离Delphi环境试试
 
脱离了Delphi后,一运行就自动关闭退出了
 
应该是你的程序写得有问题
这个错误好像是内存溢出了贴出程序段看看
 
procedure TMTDepartmentForm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
inherited;
DrawCell(sender,Rect,DataCol,Column,State);
end;

procedure TMTDepartmentForm.FormCreate(Sender: TObject);
begin
inherited;
lblInfo.Caption:='全校共有'+IntTostr(ADOQuery.RecordCount)+'个院系';

end;

procedure TMTDepartmentForm.ToolButton1Click(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbFirst);
end;

procedure TMTDepartmentForm.tbtnPriorClick(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbPrior);
end;

procedure TMTDepartmentForm.tbtnNextClick(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbNext);
end;

procedure TMTDepartmentForm.ToolButton4Click(Sender: TObject);
begin
inherited;

DBNavigator1.BtnClick(nbLast);
end;

procedure TMTDepartmentForm.tBtnAddClick(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbInsert);
end;

procedure TMTDepartmentForm.tbtnPostClick(Sender: TObject);
begin
inherited;

// try
DBNavigator1.BtnClick(nbPost);
// except
// on EdatabaseError do
// begin
// showmessage('错误信息');
// raise;
// end;
// end;

end;

procedure TMTDepartmentForm.tBtnDelClick(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbDelete);
end;

procedure TMTDepartmentForm.tbtnEditClick(Sender: TObject);
begin
inherited;
DBNavigator1.BtnClick(nbEdit);
end;

procedure TMTDepartmentForm.ADOQueryBeforePost(DataSet: TDataSet);
var
i:integer;

begin
inherited;
for i:=0 to adoQuery.fieldCount-2 do
begin
if adoquery.Fields.AsString='' then
begin
application.MessageBox('请先把信息填写完整!','',MB_OK+MB_IconInformation);
abort;
adoquery.Fields.FocusControl;
end;
end;
adoquery.First;
if adoQuery.Locate('XSH',dbtxsh.Text,[]) then
begin
showmessage('record repeat!');
abort;
end;
end;

procedure TMTDepartmentForm.ADOQueryBeforeDelete(DataSet: TDataSet);
begin
inherited;
if Application.MessageBox('确定要删除选定记录吗?','提示',
MB_YesNoCancel+MB_IconQuestion)<> IDYes then
abort;

end;

end.
 
 怎么没消息啦???

 请帮忙!!!!
 

Similar threads

I
回复
0
查看
763
import
I
I
回复
0
查看
618
import
I
I
回复
0
查看
843
import
I
I
回复
0
查看
796
import
I
后退
顶部