Gary's Delphi Client Dataset Based Application
Problems with TClientDatasets and their solutions:
TableName := 'name of the table you wish to update';
For more complex scenarios, such as allowing the editing and updating of multiple tables, you need to write some code yourself. There are two approaches to solving this problem:
However, the problem in using this technique in MIDAS becomes readily apparent when you try to do this for the first time. The TUpdateSQL.Dataset property is declared as a TBDEDataset. Because the Delta dataset is a TDataset, we cannot make this assignment legally. Rather than give up and use the DatasetProvider.BeforeUpdateRecord method of applying updates, I created a TUpdateSQL component descendant that will work seamlessly when resolving multi-table joins. The key to writing this component was to change the Dataset declaration to TDataset, and override the Apply method so we can call our own version of SetParams that will bind parameters to the target TDataset. Additionally, SessionName and DatabaseName properties were exposed to allow the update to occur in the same context as other transactions. The resulting code for the TQuery.OnUpdateRecord event is shown in Figure 10.
procedure TJoin2Server.JoinQueryUpdateRecord(DataSet: TDataSet;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
usqlEmp.SessionName := JoinQuery.SessionName;
usqlEmp.DatabaseName := JoinQuery.DatabaseName;
usqlEmp.Dataset := Dataset;
usqlEmp.Apply(UpdateKind);
usqlFTEmp.SessionName := JoinQuery.SessionName;
usqlFTEmp.DatabaseName := JoinQuery.DatabaseName;
usqlFTEmp.Dataset := Dataset;
usqlFTEmp.Apply(UpdateKind);
UpdateAction := uaApplied;
end;