RAD Studio
ContentsIndex
PreviousUpNext
Editing Delta Packets Before Updating the Database

Before a dataset provider applies updates to the database, it generates an OnUpdateData event. The OnUpdateData event handler receives a copy of the Delta packet as a parameter. This is a client dataset. 

In the OnUpdateData event handler, you can use any of the properties and methods of the client dataset to edit the Delta packet before it is written to the dataset. One particularly useful property is the UpdateStatus property. UpdateStatus indicates what type of modification the current record in the delta packet represents. It can have any of the values in the following table:  

UpdateStatus values  

Value 
Description 
usUnmodified  
Record contents have not been changed  
usModified  
Record contents have been changed  
usInserted  
Record has been inserted  
usDeleted  
Record has been deleted  

For example, the following OnUpdateData event handler inserts the current date into every new record that is inserted into the database:

procedure TMyDataModule1.Provider1UpdateData(Sender: TObject; DataSet: TCustomClientDataSet);
begin
  with DataSet do
  begin
    First;
    while not Eof do
    begin
      if UpdateStatus = usInserted then
      begin
        Edit;
        FieldByName('DateCreated').AsDateTime := Date;
        Post;
      end;
      Next;
    end;
end;

 

void __fastcall TMyDataModule1::Provider1UpdateData(TObject *Sender, TCustomClientDataSet *DataSet)
{
  DataSet->First();
  while (!DataSet->Eof)
  {
    if (DataSet->UpdateStatus == usInserted)
    {
      DataSet->Edit();
      DataSet->FieldByName("DateCreated")->AsDateTime = Date();
      DataSet->Post();
    }
    DataSet->Next();
  }
}
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!