views:

188

answers:

5

Some background: I want to develop a desktop application, with a SQL database as storage. There is only one user at one time connected to the database.
To make maintainance easier, I would like to seperate GUI from Busniss Logic. Thus, I thought using a DataModule (where the BL is implemented), for each Dialog.

My question: Where is the proper place to insert a TClientDataset component? Directly in the Dialog or in the DataModule?

+2  A: 

If the TClientDataSet will not be used by more then one screen at the same time, it is safe to place them on a DataModule for convenience. However, when you have two or more screens accessing the same TClientDataSet you will have a problem since the dataset only has one cursor and moving to another record on one screen will also move to another record on the other screens. In that case: put the TClientDataset on the screens that use the data. The connection can still be put on the datamodule since it is shared by all datasets.

birger
+4  A: 

Personaly, I place TDataset-descendants always in a datamodule. Should you, at some point, decide to redesign your forms, you still have your datasets at your disposal. Sharing information between forms is then easier as well. In general, keep your GUI and data seperate!

Brave Cobra
+2  A: 

I would put the DataSets in DataModules. That way, you can have multiple Views in different Forms pointing on the same DataSet, like a Details View and a List in a Grid, and they will always be in sync automatically.
It also formalizes the separation between Data with the business rules and User Interface with presentation features, making it easier to change the business rules or redesign the UI independently.
And if you need to have multiple instances of the Forms accessing different Data, you can always instantiate multiple DataModules and hook each Form to its relevant one.

François
+1  A: 

Datasets in the Data Module - but DataSources on the form or frame - has always worked well for me.

RichardS
Why did you put the TDataSource on form and not next to the ClientDataset?
max
A number of reasons: Often you will want to respond to events in the TDataSource which affect the form containing the data controls. If the DataSource is on the data module, the data module has to know about the form in order for those events to work, which leads to tighter and unwanted coupling. You should think of the DataSource as the "bridge" between the form and the data module - and remember, more than one form may want to use that data module, so each should have their own DataSource(s) connecting to it.
RichardS
+1  A: 

The datasnap way:

  • have BL datamodules with the data access layer and TDatasetProvider components, plus the business code
  • have datamodules just with the TClientDatasets.

This way if you change the implementation to a n-tier using DataSnap (or other n-tier technology where you can reuse the clientdatasets), you just have to move the BL datamodules to the appropriate tier.

Fabricio Araujo
Shouldn't the business code be in the layer with the TClientDataSets?
RichardS
It's just the DataSnap way. In that way, clientdatasets remain on the interface, and the providers(and data access) go to the other tier.This would easy the transition to a 3-tier architecture using that framework... ;-)
Fabricio Araujo
Interesting, thanks. Hadn't thought of doing it that way.
RichardS