Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the TDataSource component?

Tags:

delphi

When I split code into TDataModule (=access data) and TFom (=display data), where should I put the TDataSource component? Does it belong to the TDataModule or TForm?

And how to handle connenctions between the TDataModule and TForm, when multiple instances are created?

like image 826
markus_ja Avatar asked Apr 12 '12 13:04

markus_ja


2 Answers

I would put the Datasources in the Form, since it is only a component to use with visual controls.

Also, you can create Datasouces on demand in the form when needed and bind then at runtime to the datasets. In that case it is easy to handle connections between the TDataModule and TForm.

But that's is just MY opinion: I would never use DBControls nor DataSouces. I prefer to bind my data by hand and have more flexibility than using DBControls and DataSouces and be stick to some weird mechanics Borland created. But that is just MHO.

like image 89
Rafael Colucci Avatar answered Nov 20 '22 16:11

Rafael Colucci


It is recomended to put your TDatasource components in the Form, but only if the data linked to them is only used by the parent form or any child of it.

Also is recommended to put your TDatasource components on a global TDatamodule when they are linked to global accesible data or list data, like a list of client, countries, etc. Data that may be used in more than one form in your application.

For example, if you have a TDBLookupCombo, the TDatasource assigned to ListSource property, is a good candidate to be on a TDatamodule.

like image 1
Christopher Ramírez Avatar answered Nov 20 '22 15:11

Christopher Ramírez