Delphi db aware components


I want a component which will list the values in a database table to a field but I do not need to return the the selected value. I want to display the contents of the table but I do not need to update it do I still use a dbcombobox or do I use a regular combobox perform a query a loop through the results to populate the combobox?


Who is Participating?
Hi. You should use a DBLookupComboBox.
To populate the 'list' you will use ListSource - and give it a datasource, Keyfield - and give it an indexed field in that table (I usually just put the field whose list I want to be shown, but best practise is to put any indexed field), and finally set 'List Field' to the field whose list you want to be shown.

You would only need to use a loop through a table to add its results IF that table wasn't uni-directional, i.e. if your table can only show one record/row at a time.
You would only need to use a loop through a table to add its results IF that *dataset* *was* uni-directional, such as DBexpress.
There are other cases where I have opted to do a loop-through, but that isn't strictly 'data-aware' and therefore isn't best practise. Where possible, use a DBLookupComboBox and use the ListSource.
Oh, and in the DBLookupCombobox, make sure you set the Datasource and DataField properties blank.
Then once the user has selected you can say
DBLookupComboBox1.text to read the string value of the box.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.