继续this question,当使用FireDac并且调用BeforePost事件到一个调用Abort的函数时,会导致完整的系统中止,从而打破在该中止周围运行的循环。
while not fdOtherQuery.eof do begin
fdQuery.insert;
fdquery.fields[0].asstring := fdOtherQuery.fields[0].asstring;
fdquery.post;
fdOtherQuery.next;
end;
发布前:
procedure TForm1.AzureDayarKriaAdditionsBeforePost(DataSet: TDataSet);
begin
calculcation;
end;
procedure calculaction;
begin
if fdQuery.fields[0].asstring = 0 then abort;
end;
如果调用计算中止,则
虽然没有fdOtherQuery.eof开始
也是停止的
答案 0 :(得分:2)
Abort引发了一个无声的异常,可以通过try ...来捕获。
while not fdOtherQuery.eof do begin
fdQuery.insert;
fdquery.fields[0].asstring := fdOtherQuery.fields[0].asstring;
try
fdquery.post;
except
on E: EAbort do
begin
// log the error (when needed)
end;
end;
fdOtherQuery.next;
end;