在beforepost里面判断, if xxxx then begin //......... abort; end; if xxxx then begin //..... abort; end;
或者 procedure TForm1.Button1Click(Sender: TObject); begin try with ADOQuery1 do begin //Close; //Execsql; end; except on EOleException do begin ShowMessage('Error'); end; end;
try
except on E:EOleException do begin Application.ShowException(E); Exit; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin try with ADOQuery1 do begin //Close; //Execsql; end; except on EOleException do begin ShowMessage('Error'); end; end;
以下代码在Delphi6.0 / Oracle8.1.7 / Win2000 Professional下测试通过,没有你所说的问题: procedure TForm1.FormCreate(Sender: TObject); begin if ADOConnection1.Connected then ADOConnection1.Connected := False; ADOConnection1.ConnectionString := 'Provider=MSDAORA.1;Password=manager;User ID' +'=system;Data Source=Server;Persist Security Info=True'; ADOConnection1.Connected := True; with ADOQuery1 do begin SQL.Text := 'select TABLE_NAME from user_tables where ' + 'TABLE_NAME = ''ABC'''; open; if Fields[0].AsString = '' then begin Close; SQL.Text := 'Create table ABC (f1 varchar2(10),' +'f2 varchar2(10),' +'primary key(f1))'; ExecSQL; end; end; end;procedure TForm1.BitBtn1Click(Sender: TObject); begin with ADOQuery1 do begin if Active then Close; SQL.Text := 'insert into abc values (''111'', ''222'')'; try ExecSQL; except ShowMessage('没插进去!'); end; end; end;
on E:exception do
application.MessageBox(pchar(E.Message),'Info',mb_ok+mb_iconinformation);
end;
...
except
on Exception....
...
end;
在delphi中运行会显示所有异常,而实际运行就不会了
if xxxx then
begin
//.........
abort;
end;
if xxxx then
begin
//.....
abort;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
with ADOQuery1 do
begin
//Close;
//Execsql;
end;
except
on EOleException do
begin
ShowMessage('Error');
end;
end;
except
on E:EOleException do
begin
Application.ShowException(E);
Exit;
end;
end;
SQl.Add('insert into table1 (c1,c2) values(''aaa'',''bbb'')');
也可以创建一个E:EOleException 异常类
except
end;--------------------------------------- 欢迎访问 http://www.coderpub.com 技术论坛
ADOQuery1.SQl.Text := 'insert into table1 (c1,c2) values(''aaa'',''bbb'')');
try
ADOQuery1.ExecSQL;
except
ShowMessage('妈的!怎么出错了!');
end;
ADOQuery1.SQL.Text := 'insert into table1 (c1,c2) values(''aaa'',''bbb'')';
ADOQueryRole_Pur.Close;
ADOQueryRole_Pur.SQL.Clear;
ADOQueryRole_Pur.SQL.Text := 'insert into T_ROLE_PRIVILEGE(ROLE_ID,PRIV_ID) values('''+RoleID+''','''+PurID+''')';
try
self.ADOQueryRole_Pur.ExecSQL;
except
ShowMessage('出错了!');
end;总是弹出数据库自己的 的出错信息!就是不执行我自己的
begin
try
with ADOQuery1 do
begin
//Close;
//Execsql;
end;
except
on EOleException do
begin
ShowMessage('Error');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if ADOConnection1.Connected then
ADOConnection1.Connected := False;
ADOConnection1.ConnectionString := 'Provider=MSDAORA.1;Password=manager;User ID'
+'=system;Data Source=Server;Persist Security Info=True';
ADOConnection1.Connected := True;
with ADOQuery1 do
begin
SQL.Text := 'select TABLE_NAME from user_tables where '
+ 'TABLE_NAME = ''ABC''';
open;
if Fields[0].AsString = '' then
begin
Close;
SQL.Text := 'Create table ABC (f1 varchar2(10),'
+'f2 varchar2(10),'
+'primary key(f1))';
ExecSQL;
end;
end;
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
if Active then Close;
SQL.Text := 'insert into abc values (''111'', ''222'')';
try
ExecSQL;
except
ShowMessage('没插进去!');
end;
end;
end;