Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Delphi Databases > Re: Best practi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 942 of 987
Post > Topic >>

Re: Best practices for datbase connection?

by Dan <Doculus at CMDCsystems dot com> Oct 18, 2006 at 08:54 AM

On 18 Oct 2006 04:47:26 -0700, MorrganMail@[EMAIL PROTECTED]
 wrote:

>Hi,
>
>I am currently writing an application in Delphi 5 which is supposed to
>connect to and diagnose Access databases using BDE. Since I am an
>inexperienced Delphi programmer I was hoping that you could help me out
>by sharing your best practices with me concerning database interaction.
>
>Where to put database connection?
>My initial thought is to put the database connection in the main form.
>Creating and opening it in the constructor, destroying and closing in
>the destructor.

Put them in a DataModule
>
>Where to put DataSources?

Put them in the same DM

>Since many DataAware controls can connect to the same DataSource it
>seems to me that it belongs in a DataModule?

Yes
>
>How many DataModules?
>Should I use one big DataModule for all Querys and DataSources or
>should I have one DataModule for each pair of them or maybe something
>in between?
>
As many as you need ;) I like to keep the total number of lines in the
unit below a few hundred, so it is easier to find things. The form can
have quite a few objects on it, such as queries, data sources, etc. as
long as there isn't much code associated with them. It makes no
difference in the final executable size or the processing speed. Make
it easy on yourself.

>How to connect Querys to database?
>As I have understood this is just a matter of using the same database
>name for the connection as well as the Queries?

Yes. Using the BDE to connect, which is probably what you will start
with, drop a TDatabase object on your dm, give it a meaningful name,
say dbMain. Then drop a TQuery object on the dm. Click the
DatabaseName property in the object inspector, and you should se
dbMain listed. Select it.
>
>How to change database on the fly?
>Just change the alias for the connection?

Look up TDatabase.DatabaseName in the Help for details. This is a bit
complicated at first. I recommend using an alias for the database; it
makes program development easier because it separates the connection
details from your app. Aliases are set and managed with the
BDEadministrator program which is included in your Delphi software.

If you know in advance what the different DBs are that the user will
connect to, you can use a different alias for each one, and the user
can select the desired one from a list. Your code would then change
the Alias property in the TDatabase object at runtime (while the
connection is closed).
>
>A lot of questions, hope you can bare with me. I have little time, no
>expertise around and want to get it right and write good code.
 




 2 Posts in Topic:
Best practices for datbase connection?
MorrganMail@[EMAIL PROTEC  2006-10-18 04:47:26 
Re: Best practices for datbase connection?
Dan <Doculus at CMDCs  2006-10-18 08:54:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 7:22:56 CDT 2008.