即使 ApplyUpdates 在里面,仍然会弹出错误提示 try...except [英] Still get error popup even when ApplyUpdates is inside try...except

查看:21
本文介绍了即使 ApplyUpdates 在里面,仍然会弹出错误提示 try...except的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到解决方案,见我下面的评论

D5,odbc转mysql数据库

D5, odbc to mysql database

此代码:

  with QryCmdPerf do begin
    Close;
    ParamByName('ACCTID').AsInteger:= AcctId;
    ParamByName('FROMDT').AsString:= MySQLDate(FromDt);
    ParamByName('TODT').AsString:= MySQLDate(ToDt);
    Open;
    first;
    try
      edit;
      FieldByName('PnL').AsFloat:= 97979;
      ApplyUpdates;
    except
      close;
    end;
  end;    // with

(特别是ApplyUpdates")如果 PnL 字段的值已经是 97979,显然是因为这个代码,会导致一个带有文本更新失败"的弹出窗口出现:

(specifically the "ApplyUpdates") causes a popup to appear with the text "Update Failed" if the PnL field already has the value 97979, evidently because of this code:

procedure TUpdateSQL.ExecSQL(UpdateKind: TUpdateKind);
begin
  with Query[UpdateKind] do
  begin
    Prepare;
    ExecSQL;
    if RowsAffected <> 1 then DatabaseError(SUpdateFailed);
  end;
end;

在 DBTables.pas 中.无论如何,我希望能够发出 ApplyUpdates,并且如果它不进行任何更新,则不必担心弹出窗口.但是如果try...except"不起作用,那会怎样?

in DBTables.pas. Anyway, I want to be able to issue ApplyUpdates, and not have to worry about a popup if it doesn't do any updating. But if "try...except" doesn't work, what will?

TIA

推荐答案

简短的回答是,您必须为 OnUpdateError 设置事件处理程序,否则再多的try...except"块都不会阻止弹出窗口.长答案是它似乎是 odbc 的一个错误.复制品在这里:http://www.codeupload.com/3919 对于任何想要参加看它.你可以跳过 MySQL 的东西,任何 odbc 数据库都可以.

The short answer is, you have to set up an eventhandler for OnUpdateError or no amount of "try...except" blocks will block the popup. The long answer is it appears to be a bug with odbc. The repro is here: http://www.codeupload.com/3919 for anyone who wants to take a look at it. You can skip the MySQL stuff, any odbc database will do.

这篇关于即使 ApplyUpdates 在里面,仍然会弹出错误提示 try...except的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆