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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With