Lazarus

Programming => Databases => Topic started by: guest48180 on August 13, 2019, 01:28:31 am

Title: DB Components' Question
Post by: guest48180 on August 13, 2019, 01:28:31 am
Aside from having explicit control over the database components through code, what's the difference between connecting DB components through the Object Inspector and connecting them at run time through code? During Form creation, I do the following:
Code: Pascal  [Select][+][-]
  1.   DM1.SQLite3Connection1.DatabaseName:= 'data.db';
  2.   DM1.SQLite3Connection1.Params.Add('foreign_keys=1');;
  3.   DM1.SQLite3Connection1.Connected:= True;
  4.   DM1.SQLTransaction1.Active:= True;  
But I connect my DataSources and SQLQueries in the Object Inspector.

I notice some of the more seasoned programmers here tend to stay away from the OI to wire up their DB components, doing it all through their code. Is that a best practice? Or just a preference?
Title: Re: DB Components' Question
Post by: JanRoza on August 13, 2019, 08:31:42 am
If your program is for you only there is nothing wrong with using the Object Inspector but if your program is meant to be installed by other people on different computers then I would prefer the code option as you never know for sure in what location those people will install your program.
If they use a different location than there is a big chance that your Object Inspectors database location does not exist on their computer.
By setting the database location by code you stay in control and your program will always be able to find the database.
In Windows I mostly use the Users folder or a common place like Program Data for database location. 
Title: Re: DB Components' Question
Post by: guest48180 on August 13, 2019, 08:46:16 am
Hi JanRoza:

Your feedback makes a lot of sense. The program I'm working on is meant for others to use, so I need to make sure I get this right the first time. Your input is appreciated.
TinyPortal © 2005-2018