Create Components on the fly

Posted on 2007-10-06
Last Modified: 2013-11-23
Using delphi I have a combobox which has a list of departments the user selects the appropriate department, when this is done a database is accessed and should list all the people in the department and provide an input field for each person in the department to capture some data to be returned to the database, there are varying numbers of people in each department. Would this be an area when I would create a series of components on the fly? if so how would I do this


Question by:elschott
    LVL 13

    Assisted Solution

    Hopefully someone will come along and explain how to do that,
    but in the meantime, have you considered a DBGrid and connecting it to a Query (SQL) ?
    In the query you can fetch all records but only the fields/columns that you want the user to see.
    Then if the DBGrid is connected to the Query, the results will show in the DBGrid, and here's the important part:
    It will show the information you want, and they'll just be able to click on a cell they want to over-write and just type in the new information.

    Of course this comes with some common problems:
    * Calling post. After the person has finished typing in a cell, they have to call 'post' or else the data won't sent back to the database. The good news is that if you type in a cell, and *navigate* to a different record, it will automatically post for you. THE RESULT is that the LAST record  they edit in their session won't be committed unless they call post.
    * There may be some fields that you don't want them to be able to edit. To solve this you can either change the SQL query to only bring fields you want them to edit, or set a column in the DBGrid as readonly.

    Hope this helps
    LVL 17

    Accepted Solution

    And another solution
    DBGrid (or DBList)  + a series of DBEdits
    In Dbgrid You can display only basic data Name and Last Name for example.
    In DBEdits You Can display desired for editing detailed data for a single selected in DBGrid person.
    LVL 13

    Expert Comment

    I also want to clarify what I said about using TQueries when the user has chosen the 'database' (table) that they want to see - it can be any dataset, including TTable or TADOTable and you can just set the DBGrid's DataSource to the Datasource that's connected to your dataeset.
    A Query was just a good way to do that, but some programmers (like myself) use a lot of TTables instead for certain reasons.
    LVL 27

    Assisted Solution

    use a TDBCtrlGrid

    meikl ;-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    760 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

    9 Experts available now in Live!

    Get 1:1 Help Now