Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was TDataSource created originally?

What was (or would be) the reasoning behind creating TDataSource as an intermediary between data bound components and the actual underlying TDataSets, rather than having the components just connect directly to the TDataSets themselves?

This may seem like kind of a stupid question, but I am working on a broad set of "data viewer" components, which link to a common "data connector" component, etc; and in designing this set of components, I find myself referencing the structure of the classic Delphi "TDataSet -> TDataSource -> Data-bound-component" setup for guidance. In my component set, however, I keep wanting to essentially merge the functionality of the "TDataSource" and "TDataSet" equivalents into a single class. It got me wondering what the reasoning was behind separating them in the first place.

like image 589
Jamo Avatar asked Oct 23 '09 01:10

Jamo


1 Answers

It is all about decoupling and indirection.

And with TDataSource there are two kinds of them:

  • Decoupling the master detail relations (TDataSource is in the same module as the TDataSets that are being bound; the detail TDataSet references the master TDataSet by pointing its' MasterSource property to the TDataSource that points to the master TDataSet)
  • Decoupling the UI from the business layer (TDataSets are in a DataModule; TDataSource is on the Form/Frame which contains your UI controls, UI controls reference their DataSource property).

Since many components can point to the same DataSource, you can quickly switch which underlying TDataSet they use by just flipping one TDataSource.DataSet property.

like image 99
Jeroen Wiert Pluimers Avatar answered Nov 02 '22 14:11

Jeroen Wiert Pluimers