Calling the Apply Method

From InterBase

Go Up to Executing Update Statements


The Apply method for an update component manually applies updates for the current record. There are two steps involved in this process:

  1. Values for the record are bound to the parameters in the appropriate update SQL statement.
  2. The SQL statement is executed.

Call the Apply method to apply the update for the current record in the update cache. Only use Apply when the update object is not associated with the dataset using the dataset component’s UpdateObject property, in which case the update object is not automatically executed. Apply automatically calls the SetParams method to bind old and new field values to specially named parameters in the update SQL statement. Do not call SetParams yourself when using Apply. The Apply method is most often called from within a handler for the dataset’s OnUpdateRecord event.

If you use the dataset component’s UpdateObject property to associate dataset and update object, this method is called automatically. Do not call Apply in a handler for the dataset component’s OnUpdateRecord event as this will result in a second attempt to apply the current record’s update.

In a handler for the OnUpdateRecord event, the UpdateKind parameter is used to determine which update SQL statement to use. If invoked by the associated dataset, the UpdateKind is set automatically. If you invoke the method in an OnUpdateRecord event, pass an UpdateKind constant as the parameter of Apply.

procedure TForm1.EmpAuditUpdateRecord(DataSet: TDataSet;
  UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
  IBUpdateSQL1.Apply(UpdateKind);
  UpdateAction := uaApplied;
end;

If an exception is raised during the execution of the update program, execution continues in the OnUpdateError event, if it is defined.

Note:
The operations performed by Apply are analogous to the SetParams and ExecSQL methods described in the following sections.

Advance To: