RAD Studio
ContentsIndex
PreviousUpNext
Calling the Apply Method

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

  1. Initial and edited field values for the record are bound to parameters in the appropriate SQL statement.
  2. 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 dataset and 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 code 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;
}

Executing an Update Statement

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!