Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
![]() |
![]() |
![]() |
|
IntraWeb and DataSnap
In this article, I'll describe the way for an IntraWeb application to act as DataSnap client in combination with data pooling (at the IntraWeb side).
The setup is as follows: we use a TSQLConnection and TDSProviderConnection on the Pooled Data Module in the DatamoduleUnit of the IntraWeb application.
The TClientDataSet with the disconnected data, belonging to our session, should be placed on the IntraWeb form or on the User Session unit, and not on the Pooled Data Module, since the latter is the one that's being pooled.
When the IWMainForm is created, we fill the TClientDataSet by locking the datamodule, assigning the RemoteServer and ProviderName to the TClientDataSet, and unlocking the data module (releasing it to the pool again).
procedure TIWForm2.IWAppFormCreate(Sender: TObject); var MyDataModule: TDataModule1; begin MyDataModule := LockDataModule; try ClientDataSet1.SetProvider(MyDataModule.DataSetProvider1); ClientDataSet1.Open; ClientDataSet1.SetProvider(nil) finally UnlockDataModule(MydataModule) end end;
Then, editing and posting will just work on the local TClientDataSet (disconnected from the TDataSetProvider).
As soon as we click on the ApplyUpdates button, the data module is locked (retrieved from the pool), and the RemoteServer and ProviderName properties of the TClientDataSet are assigned again, and ApplyUpdates is called. Then, we should not forget to unlock the data module again.
procedure TIWForm2.IWButton2Click(Sender: TObject); var MyDataModule: TDataModule1; begin MyDataModule := LockDataModule; try ClientDataSet1.SetProvider(MyDataModule.DataSetProvider1); ClientDataSet1.ApplyUpdates(-1); ClientDataSet1.Refresh finally UnlockDataModule(MydataModule) end end;
Using this approach, we call the LockDataModule and UnlockDataModule always in the same method, and will never keep it locked (we either unlock it in the FormCreate, or just after the call to ApplyUpdates).
A more detailed example of this approach will be included in a forthcoming update of the IntraWeb XI courseware manual in PDF format (and probably also added to the DataSnap manual).