Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
935 views
in Technique[技术] by (71.8m points)

delphi - Still get error popup even when ApplyUpdates is inside try...except

Solution found, see my comment below

D5, odbc to mysql database

This code:

  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

(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;

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're confusing the dialog displayed by the debugger with a dialog displayed by your program. Please see this article I wrote a few years ago:

It describes several ways to avoid the debugger interfering:

  • Use "advanced breakpoints" to temporarily disable the debugger around the code that throws exceptions.
  • Configure the debugger to ignore certain exception types. (Read the debugger's message more carefully to see exactly what exception class you're dealing with.)
  • Configure the debugger not to interrupt on any exceptions.
  • Turn off integrated debugger entirely.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...