Where to place the TDataSource component?

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

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

+7
source share
2 answers

I would put Datasources on the form, as it is only a component for use with visual controls.

In addition, you can create Datasouces on demand in the form when necessary, and bind it at run time to data sets. In this case, it is easy to handle the connections between the TDataModule and TForm.

But this is just MY opinion: I would never use DBControls and Datasouces . I prefer to bind my data manually and have more flexibility than using DBControls and Datasouces , and stick to some strange mechanics created by Borland. But this is just an MHO.

+10
source

It is recommended that you place TDatasource components on the form, but only if the data associated with them is used only by the parent form or by any child element.

It is also recommended that you place TDatasource components in the global TDatamodule when they are associated with globally available data or list data, such as customer list, country, etc. Data that can be used in several applications in your application.

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

0
source

All Articles