Lazarus

Programming => Databases => Topic started by: Raul_ES on August 14, 2020, 06:18:25 pm

Title: Data Aware Components: When & why to use them?
Post by: Raul_ES on August 14, 2020, 06:18:25 pm
Hello,


I am really new in database programming and I have basic skills from the CS degree (all sql).  I am used to grab data from a database (dbase for its simplicity) and put it in a string grid, edit box, whatever is expected to be placed. Just a few newbie questions:

What are the benefits of using data aware components? What actually means a component to be "data aware" capable?


Why I should use them? When?


It is always advisable to use them? There is any particular situation where we shall avoid using them?


Thank You,



Title: Re: Data Aware Components: When & why to use them?
Post by: wp on August 14, 2020, 06:59:42 pm
Basically, you can create an application without writing a single line of code (well - in practice I'd still recommend to type a few lines... -- see below):
OK - I don't want to give a database tutorial here. Just one remark, though: Your application will fail to run and even to load when the dbf file is not found at the location you specified. It is highly recommended to turn off the "Active" property of the component after the first tests and to turn it on only at runtime by code, e.g. in the OnCreate event of the form:

Code: Text  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if FileExists(Dbf1.FilePathFull + Dbf1.TableName) then
  4.     Dbf1.Active := true
  5.   else
  6.     ShowMessage('Database file not found.');

Hopefully this gets you started.

Title: Re: Data Aware Components: When & why to use them?
Post by: mangakissa on August 18, 2020, 09:21:30 am
If you want fully control of your components then dbcomponents are not the way. The most ORM applications doesn't use dbcomponents. I have managed (for my self) to create a basic tool thats fills data in an TEdit, TCombobox, TCheckbox, TListview and TStringlist. But it is a lot of work and I notised it's a lot faster than dbcomponents.

Just like WP said: they are easy to use with a few components on form. The datalink is doing the trick for you showing data in your components. 90% of my applications running on dbcomponents.
Title: Re: Data Aware Components: When & why to use them?
Post by: Raul_ES on August 22, 2020, 11:21:15 am
Thank you for your comments wp and magakissa,


regards

TinyPortal © 2005-2018