如何在运行时获得一个FMX TComboBox的Item.LookupData和SelectedValue(作为整数)? [英] How to get Item.LookupData and SelectedValue (as integer) of an FMX TComboBox at runtime?
问题描述
在FMX表单上有一个 ComboBox
。它以以下方式与数据源(具有 id
-integer和 specialty
- varchar字段)绑定 -
There is a ComboBox
on the FMX Form. It is binded with a datasource (table that has an id
-integer and speciality
- varchar fields) in the following manner-
object LinkFillControlToField1: TLinkFillControlToField
Category = 'Quick Bindings'
Control = ComboBox1
Track = True
FillDataSource = BindSourceDB1
FillValueFieldName = 'id'
FillDisplayFieldName = 'speciality'
AutoFill = True
BufferCount = -1
AutoBufferCount = False
FillExpressions = <>
FillHeaderExpressions = <>
FillBreakGroups = <>
end
访问所选 specialty
(来自 ComboBox1.Selected.Text
),但我找不到访问 id
所选项的值,没有额外的SQL请求。它在哪里存储在TComboBox或其ListBox? SelectedValue
在哪里存储以及如何获取它(作为整数)?
It is simple to get access to the value of chosen speciality
(from ComboBox1.Selected.Text
) but I can not find a way to access the id
value of the selected item without extra SQL requests. Where is it stored in TComboBox or its ListBox? Where is SelectedValue
stored and how to get it (as integer)?
推荐答案
p>我目前使用以下方式来解决问题。
我以下列方式处理 OnFillingListItem
事件,并在 ComboBox
项目中存储id号。我使用标签
属性,虽然它不是很好。
I am currently using the following way to resolve the issue.
I handle OnFillingListItem
event in the following way and store id number in ComboBox
Items. I use Tag
property though it is not actually good.
procedure TForm1.LinkFillControlToField1FillingListItem(Sender: TObject;
const AEditor: IBindListEditorItem);
begin
(AEditor.CurrentObject as TListBoxItem).Tag :=
YourLookuptable.FieldByName('id').AsInteger;
end;
稍后我从ListBox1.Selected.Tag中获取Item id。这给了我一个可靠的ID。
Later on I fetch the Item id from ListBox1.Selected.Tag. This gives me a reliable ID.
这篇关于如何在运行时获得一个FMX TComboBox的Item.LookupData和SelectedValue(作为整数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!