Fires if an exception is generated when updates are applied to a database.
Use the OnUpdateError event handler to respond to exceptions raised while applying immediate or cached updates to a database.
ASender is the dataset to which updates are applied.
AException is a pointer to a EADException object from which an application can extract an error message and the actual cause of the error condition. The OnUpdateError handler can use this information to determine how to respond to the error condition. In most cases AException object will be of class EADDBEngineException or even one of it DBMS specific subclasses.
ARow is a DatS row object, repesenting erroneous record in dataset. This record is also current record in ASender.
ARequest indicates whether the error occurred while inserting, deleting, or modifying a record.
AAction indicates the action to take when the OnUpdateError handler exits. On entry into the handler, AAction is always set to eaDefault, which leads to uaFail, if not changed. If OnUpdateError can handle or correct the error, set AAction to uaRetry before exiting the error handler. Or consider other options.
The error handler can use the OldValue and NewValue properties TField to evaluate error conditions and set NewValue to a new value to reapply. In this case, set AAction to uaRetry before exiting.
The code in an OnUpdateError handler must not call any methods that make a different record the current one !
property OnUpdateError: TADUpdateErrorEvent;
procedure TForm1.ADQuery1UpdateError(ASender: TDataSet; AException: EADException; ARow: TADDatSRow; ARequest: TADUpdateRequest; var AAction: TADErrorAction); begin if (E is EADDBEngineException) and (EADDBEngineException(E).Kind = ekUKViolated) then begin DataSet.FieldByName('ID').AsInteger := GetNextFreeID; Action := eaRetry; end; end;
What do you think about this topic? Send feedback!