The task is firemonkey, it’s necessary that the data of one column are output to the combobox via livebindings, it’s simple, but there are no correct descriptions of this thing. Found a solution to this problem, I need help in translating this link TDBLookupCombobox FireMonkey .
translation of the article (literal, not prom. Some words did not translate, because it is not necessary). ControlExpressions can be understood as the values that we have as a result, and SourceExpressions are the initial values that we squeeze from the tables.
I do not know if there is a better instruction here, but here’s how I do it:
Suppose you have Table1 and a foreign key to Table2.
- Make the search field in Table1 with an external key
- Use TBindList to populate the Text property of the ComboBox component from the required field in Table 2, and fill the Tag property with the main key of Table 2
- Use TBindPosition to compare the selected text with the search field and Selected.Tag with the foreign key to Table1
Check the SourceComponent property of your TBindList and TBindPosition .
The TBindList must point to the BindScopeDB of Table2.
TBindPosition instead of BindScopeDB Table1.
ControlComponent should point to your TComboBox
When you use TBindList , the generated recordset refers to the same object inside the ComboBox , because each row of Table2 is run through for filling. Therefore, for ControlExpressions you need properties: Text and Tag .
Note : You do not need the Selected property.
and this is SourceExpressions:
Add these expressions to the set of records to be created.
TBindPosition always refers to the entire set of ComboBox objects, so you need to use the Selected property.
Remember that the PosSource set is used for the assignments "ControlExpressions to SourceExpressions" when PosControl contains the assignments "SourceExpressions to ControlExpressions".
Initially, you need two things: change the selected object when the position in Table 1 changes and force your FK (I do not know what it is) to use the Tag property of the selected object when the user changes it.
So just put this in your PosControl kit .
And it will be in your set PosSource
If you want to get similar behavior of the TDBLookupComboBox component , you need to set the Table to the editing state when the selected object is changed in the combo box.
and the key phrase:
For more informations look for the examples included with XE2.
It is necessary to use BindList and if you need to change the position of the cursor in the DataSet still BindPosition.
- In BindList we double-click on it, go to Format in Control Self.Text, in Source AsString. In the BindList itself we specify the name of the control and the name of the source and the field where to get the data for filling.
- In BindPosition we poke twice, go in PosControl - in Control - ItemIndex, in Source - RecNo-1; in PosSource - in Control - ItemIndex + 1; in Source - RecNo; and last PosClear - in Control - ItemIndex, in Source - -1.