Calling the Apply Method
Go Up to Using Multiple Update Objects Index
Note: The Borland Database Engine (BDE) has been deprecated, so it will not be enhanced. For instance, BDE will never have Unicode support. You should not undertake new development with BDE. Consider migrating your existing database applications from BDE to dbExpress.
The Apply method for an update component manually applies updates for the current record. There are two steps involved in this process:
- Initial and edited field values for the record are bound to parameters in the appropriate SQL statement.
- The SQL statement is executed.
Call the Apply method to apply the update for the current record in the update cache. The Apply method is most often called from within a handler for the dataset's OnUpdateRecord event or from a provider's BeforeUpdateRecord event handler.
Warning: If you use the dataset's UpdateObject property to associate the dataset and the update object, Apply is called automatically. In that case, do not call Apply in an OnUpdateRecord event handler, as this will result in a second attempt to apply the current record's update.
OnUpdateRecord event handlers indicate the type of update that needs to be applied with an UpdateKind
parameter of type TUpdateKind. You must pass this parameter to the Apply method to indicate which update SQL statement to use. The following example illustrates this, using a BeforeUpdateRecord event handler:
procedure TForm1.BDEClientDataSet1BeforeUpdateRecord(Sender: TObject; SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind; var Applied: Boolean);
begin
with UpdateSQL1 do
begin
DataSet := DeltaDS;
DatabaseName := (SourceDS as TDBDataSet).DatabaseName;
SessionName := (SourceDS as TDBDataSet).SessionName;
Apply(UpdateKind);
Applied := True;
end;
end;
void __fastcall TForm1::BDEClientDataSet1BeforeUpdateRecord(TObject *Sender,
TDataSet *SourceDS, TCustomClientDataSet *DeltaDS, TUpdateKind UpdateKind, bool &Applied)
{
UpdateSQL1->DataSet = DeltaDS;
TDBDataSet *pSrcDS = dynamic_cast<TDBDataSet *>(SourceDS);
UpdateSQL1->DatabaseName = pSrcDS->DatabaseName;
UpdateSQL1->SessionName = pSrcDS->SessionName;
UpdateSQL1->Apply(UpdateKind);
Applied = true;
}