Delphi db aware components

Posted on 2007-10-02
Last Modified: 2013-11-23

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?


Question by:elschott
    LVL 13

    Accepted Solution

    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.
    LVL 13

    Expert Comment

    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.
    LVL 13

    Assisted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now