
ComboBox that shows "Name" and returns "Value"?
go> What I need to do is show the user a ComboBox that contains friendly
go> names for database fields. When he selects one, I need to retrieve
go> the actual database name. So I want to fill the ComboBox.Items with
go> strings like 'Customer Name=CNAME'. I want the box to only show the
go> user 'Customer Name'. Then my code can retrieve the actual field name
go> 'CNAME'.
Look for Objects property, and AddObject method for TlistBox. You can
use any record type as attached object for each item in a listbox.
When user selects Item, take its index, and see record value attached
as object to that Item.
go> Now, obviously, I could maintain two separate lists, and use the
go> ComboBox.ItemIndex to look up the field name in a separate list. But
go> I want to keep the values together so that a later programmer cannot
go> accidentally change one and not the other.
There is no need for that approach. First time I needed similar thing,
I did use two separate lists. Hopefully maintenance of those lists was
easy so I had no problems, except I had to take care to keep both lists
in sync.
When I realized what Objects property is for, I solved a problem. You
may do whatewer you want with items: sort, exchange, add, insert or
delete, attached objects stays in sync with items they are attached
for.