Update and Maintain dbExpress's Unidirectional, Read-Only Datasets (cont'd)


SQLClientDataSet: The Three-in-One Solution
Apart from using a TSQLDataSet that uses a TDataSetProvider to put the records in a TClientDataSet component, we could also have used a TSQLClientDataSet component that in effect contains the three aforementioned components in one. This means that we should also respond to the OnAfterPost and OnAfterDelete event handlers, only this time we must make sure to cast the DataSet argument to a TSQLClientDataSet (which unfortunately is not derived from a TClientDataSet).
procedure TForm1.SQLClientDataSet1AfterPost(DataSet: TDataSet);
begin
  (DataSet AS TSQLClientDataSet).ApplyUpdates(-1)
end;
It feels a bit unsatisfying that we do not have a uniform (single-source) solution for both the TClientDataSet and TSQLClientDataSet events—yet.

A Uniform and Reusable Solution
Although TSQLClientDataSet isn't derived from TClientDataSet (so we can't just use the "Sender AS TClientDataSet" for a TSQLClientDataSet), both are in fact derived from TcustomClientDataSet. So we should just change our code to be uniform and reusable:

procedure TForm1.SQLClientDataSet1AfterPost(DataSet: TDataSet);
begin
  (DataSet AS TCustomClientDataSet).ApplyUpdates(-1)
end;
This should be connected to the OnAfterPost as well as the OnAfterDelete event handlers. It can operate on both the regular TClientDataSet and the TSQLClientDataSet components.

And of course, in both cases you still should respond to the OnDestroy or OnClose event handler to make sure the final change is taken into account as well—before you close your application.



Bob Swart (aka Dr.Bob) is a Delphi trainer and consultant who has spoken at the Borland Developer Conferences since 1993. As a freelance technical author, he has written chapters for The Revolutionary Guide to Delphi 2 (WROX), Delphi 4 Unleashed, C++ Builder 4 Unleashed, C++ Builder 5 Developer's Guide, and the upcoming Kylix Developer's Guide and Delphi 6 Developer's Guide (SAMS). He can be reached at drbob@chello.nl.



Previous: Read-Only, Unidirectional Datasets
 
Back to Introduction


Introduction SQLClientDataSet: The Three-in-One Solution
Read-Only, Unidirectional Datasets


Return to Get Help with Delphi Page

Return to Main Get Help Page
 
How do I post a new or changed record to a dbExpress dataset when dbExpress provides only unidirectional, read-only datasets?




Use some available components to create solutions that will maintain your dbExpress dataset updates.


Find Out More
• Get the source code for this Solution!

• The DevX Database Development Zone

• Previous 10-Minute Solution: Migrate Your BDE Applications to Linux with dbExpress

• Dr. Bob's Delphi Clinic

TALK BACK
Do you expect dbExpress to replace the Borland Database Engine, especially since Kylix supports only dbExpress? Let us know in the Database Development discussion groups!
 





Sponsored Links