We have a Members table containing a field (as integer) to define the "status of membership" by his id. By example: 0 for Inactive, 1 for Active, 2 for LifeTime, 3 for Retired, 4 for Exceptional Achievement, etc,
We have a StringGrid attach to the Members table with LiveBindings. So, in the grid we see the id number of the status (1 or 2 or Etc.). But we want to see the "Labels" of that status (ex: LifeTime) and not his id.
For information, the "status label" cannot be store in a Lookup table because it have to be translated in different language.
I've created an object containing the status ObjMemberStatus:TObjectList<TMemberStatus>;
that hold membership labels using a TAdapterBindSource.
I was able to assign this information to a ComboBox using a TDataGenerator. I think it's the way to do with ComboBox in that situation, and this is working very well for that.
My question is: how can I display the label contained in a AdapterBindSource to a column of a grid ?
I've perform some search and I did not see how to do that directly with LiveBindings. Maybe I've missied somethings.
I've also seen in the help that we can add that method: Lookup(scope lookup, key fields, key values, result fields) to the CustumFormat property. But no example show how to use that CustumFormat Method. I've search on the web for that and it seem to be undocumented.
Sub-Questions, there is a way to bypass or hook some code into the LiveBindings data assignation to component process ?
You seem to be making heavy weather of this.
I appreciate that there is the complication of translation, but the most straightforward thing to do is simply to apply the KISS principle and add a calculated field to the dataset which provides a textual representation of the membership status.
To handle the translation, the cleanest way would of course be to have a separate table of membership status texts for different languages and select the language to use at runtime. If you don't want to be bothered with that, just use the
Valuesproperty of aTStringListto look up the translations in the grid DataSet's OnCalcFields event.Update It is incorrect to say that you can add calculated fields to an FDQuery but not to an FDMemtable. The following code works fine:
and correctly displays both columns, ID and Description, in a live-bound StringGrid.