Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2010, 07:03 AM
vishualsoft vishualsoft is offline
Senior Member
 
Join Date: Jan 2010
Location: Bangalore, India
Posts: 294
Question When to use TDataModule form ?

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
Reply With Quote
  #2  
Old 05-03-2010, 04:28 PM
ONEz ONEz is offline
Junior Member
 
Join Date: Mar 2010
Posts: 1
Default

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!
Reply With Quote
  #3  
Old 05-04-2010, 08:12 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,836
Default

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...
Reply With Quote
  #4  
Old 05-04-2010, 05:34 PM
vishualsoft vishualsoft is offline
Senior Member
 
Join Date: Jan 2010
Location: Bangalore, India
Posts: 294
Smile

Hi Thank You Norrit and ONEz.

Thanks for the replay.


I found here proper answer.


Thanks once again.

Regards.

Vishal
Reply With Quote
  #5  
Old 09-16-2011, 04:50 AM
Zei54Nol Zei54Nol is offline
Junior Member
 
Join Date: Sep 2011
Posts: 8
Default

it's very hard to maintain your sql statements

Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:02 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2014, vBulletin Solutions, Inc.