markus_ja
markus_ja

Reputation: 2951

Where should the TClientDataset component be located?

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?

Upvotes: 3

Views: 744

Answers (5)

Fabricio Araujo
Fabricio Araujo

Reputation: 3820

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.

Upvotes: 1

RichardS
RichardS

Reputation: 536

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

Upvotes: 1

Francesca
Francesca

Reputation: 21640

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.

Upvotes: 2

Brave Cobra
Brave Cobra

Reputation: 684

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!

Upvotes: 5

Birger
Birger

Reputation: 4353

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.

Upvotes: 2

Related Questions