![]() |
|
#1
|
|||
|
|||
|
I All,
I would like to know when and why should i use the TDataModule in database application. SQL execution should be done in a TDataModule or in a unit file (a file which doesn't contain GUI form). Which is the better way for SQL execution. Or anybody can specify in a proper way how the database application should be structured. Thanks in advance. Vishal |
|
#2
|
|||
|
|||
|
TDataModule is used as a common placeholder for all database objects (connections, tables, queries, etc.).
It can be used to hold any non visible objects in your apps, like imagelist, etc. Having said that, TDatamodule serves its purpose when you have more than one form that has data aware controls which links to a common datasource, or when you have many connections/tables/queries objects. Instead of cluttering your main form, you can put them all in a TDataModule. For SQL query, I don't think that there is a specific rule of where to put the codes. You can either put it in tdatamodule, application form (which has data aware controls), or in a unit. The rule of thumb is, put it where you can easily maintain them! |
|
#3
|
|||
|
|||
|
I normally write all my queries in a separate unit, used by the datamodule. So all logic is in the datamodule, UI only calls the datamodule and does not have to know about it's logic. If somebody has to attach another database (switch from mssql to mysql), it's very hard to maintain your sql statements if you place it in your application forms...
|
|
#4
|
|||
|
|||
|
Hi Thank You Norrit and ONEz.
Thanks for the replay. I found here proper answer. Thanks once again. Regards. Vishal
|
|
#5
|
|||
|
|||
|
it's very hard to maintain your sql statements
![]() ![]()
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|