我正在编写一个 FMX Metropolis UI 应用程序,并尝试通过 LiveBindings 技术(使用表达式引擎)将两个字符串类型的字段值分配给 TListBox 的 Item.Title 成员。
当我按以下方式使用 TBindList 时:
object BindList1: TBindList
Category = 'Lists'
ControlComponent = ListBox1
SourceComponent = BindSourceDB1
FormatExpressions = <
item
ControlExpression = 'Text'
SourceExpression =
'FieldByName("name1").Text + " " + Field' +
'ByName("name2").Text'
end>
FormatControlExpressions = <>
ClearControlExpressions = <>
end
它将“name1 name2”字符串分配给成员 Text
但我无法设置 ListItemStyle := MetropolisUI
因为 TBindList 类中没有这样的属性
如果我使用TLinkFillControlToField
object LinkFillControlToField2: TLinkFillControlToField
Category = 'Quick Bindings'
Control = ListBox1
Track = True
FillDataSource = BindSourceDB1
FillDisplayFieldName = 'name1'
AutoFill = True
BufferCount = -1
AutoBufferCount = False
FillExpressions = <>
FillHeaderExpressions = <>
FillBreakGroups = <>
end
它让我分配 ListItemStyle
至MetropolisUI
,但我只能使用 FillDisplayFieldName
访问一个字段属性(property)并没有SourceExpression
要分配的字段 'FieldByName("name1").Text + " " + FieldByName("name2").Text'
到它。
我试图猜测 Item.Text
的上下文TListBox
的成员来自TBindList
但我没能做到。我研究了 Delphi 示例,但没有 Metropolis TListBox,而且它的行为方式似乎与常见的不同。有人知道如何找到此问题的解决方案吗?
最佳答案
感谢 @house-of-dexter 的帖子,他给了 answer关于TLabel
这鼓励我尝试TLinkFillControlToField
再次。主要问题是字段名的上下文可以在 Self.Owner
中找到。 .
object LinkFillControlToField2: TLinkFillControlToField
Category = 'Quick Bindings'
DataSource = BindSourceDB1
Control = ListBox1
Track = True
FillDataSource = BindSourceDB1
AutoFill = True
BufferCount = -1
AutoBufferCount = False
ListItemStyle = 'MetropolisUI'
FillExpressions = <
item
SourceMemberName = 'name1'
ControlMemberName = 'Title'
CustomFormat = 'Self.Owner.name1.text+" "+Self.Owner.name2.text'
end>
FillHeaderExpressions = <>
FillBreakGroups = <>
end
关于delphi - 使用实时绑定(bind)将多个字段值分配给 FMX MetropolisUI TListBox Item.Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31202376/