Author Topic: DB Components' Question  (Read 545 times)


  • Guest
DB Components' Question
« 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?


  • Hero Member
  • *****
  • Posts: 555
Re: DB Components' Question
« Reply #1 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. 
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.6 FPC 3.0.4 i386-win32-win32/win64
       Lazarus 2.1.0 FPC 3.3.1 i386-win32-win32/win64
       CodeTyphon 7.1 FPC 3.3.1 i386-win32-win32/win64


  • Guest
Re: DB Components' Question
« Reply #2 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.