如何在运行时获取 FMX TComboBox 的 Item.LookupData 和 SelectedValue(作为整数)? [英] How to get Item.LookupData and SelectedValue (as integer) of an FMX TComboBox at runtime?

查看:16
本文介绍了如何在运行时获取 FMX TComboBox 的 Item.LookupData 和 SelectedValue(作为整数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FMX 表单上有一个 ComboBox.它以以下方式与数据源(具有 id-integer 和 speciality-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

访问所选speciality的值很简单(来自ComboBox1.Selected.Text),但我找不到访问的方法没有额外 SQL 请求的所选项目的 id 值.它存储在 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)?

推荐答案

我目前正在使用以下方式解决该问题.我按以下方式处理 OnFillingListItem 事件并将 ID 号存储在 ComboBox 项目中.我使用 Tag 属性,尽管它实际上并不好.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆