开发者

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?


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!


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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜