Does a TDbComboBox
-like control exist, that gets its displayed values by an fixed list (to use for an enumerated type, e.g. TSomeValueEnum = (svSmall=1, svMedium=2, svLarge=3)
)?
With for instance:
1=small
2=medium
3=large
In the database I save 1 or 2 or 3, but in the ComboBox only the corresponding value should be displayed.
I ended up implementing the following workaround (using Firebird as database, other implementations will differ):
For my little problem, this seems to be enough. For "real code" I think, I would prefer a TClientDataset-based solution (as proposed by Sir Rufo)
An other alternative would be to use TDbComboBox with custom drawing as described here.
You can use a TDbLookupComboBox combined with a memory-table (fi TClientDataSet). Fill the memory-table with the desired values and the TDbLookupComboBox will do the rest.
But there is one missing link, between the stored value in database, the string representation for the UserInterface and the Enum for your application. To put all together in one place you should build a class that will handle all this conversion for you in a convenient, safe and documented-by-code way.
To fill up the memory table get the list from
TSomeValue.CreateAsList
and fill the table from that list.Raize Components has a TRzDbComboBox where you have separate lists for Items and Values.
From the help: