Delphi tip: Data-aware controls not displaying items in DataSource combo box

Have you ever had a form on which data-aware controls did not have any items in the DataSource combo box? Tom Cummings, a good friend (and co-worker) and I recently came across this problem and all of the obvious answers to solve it didn’t work. Well, last night, Tom got fed up and finally figured out what we were missing. Let me describe the scenario a little detail.

A form contains numerous data-aware controls. These controls need to point to a DataSource located in a Data Module. As expected, the form uses the DataModule. Everything up to this point looks fine. Unfortunately, every DataSource combo box does not see anything within the DataModule. The DataModule is open at design-time. Hmm. Weird. Another interesting fact is that typing in a valid, fully qualified target for the DataSource property works! Running the application works as expected as well. Sound weird? Ready for the solution?

Close the form
Add the unit name to the Project’s .dpr file! (e.g. MyForm in ‘MyForm.pas’)
Open the form

Simple, eh?

Normally, when you add a new form to a project, the reference is automatically put in the .dpr file. But if an existing form is referenced, you need to add the reference in the uses clause.

Update (3/25/2004): I thought of a better way to do this early this morning. The better way of adding an existing form to a project is to use “Add file to project” icon or menu item. This will add the reference automatically for you.

Kudos to Tom Cummings for figuring this frustrating situation out!

This entry was posted in Delphi, Tips & Tricks. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *