1
votes

I was coding an FMX metropolis application in Delphi XE5 and met the error in synchronization of datasource and TListBox. It works properly until there is a group header that unites one or more items. The selection of the first item of ListBox (ListItemStyle=MetropolisUI) in a group leads to its disappearing from the list (it becomes invisible, this does not effect the dataset itself).

object LinkListControlToField1: TLinkListControlToField
      Category = 'Quick Bindings'
      DataSource = BindSourceDB1
      FieldName = 'name2'
      Control = ListBox1
      FillExpressions = <
        item
          SourceMemberName = 'photo_mini'
          ControlMemberName = 'Icon'
        end
        item
          SourceMemberName = 'diagnosis_short'
          ControlMemberName = 'Description'
        end
        item
          ControlMemberName = 'Title'
          CustomFormat = 'self.owner.name1.text+" "+self.owner.name2.text'
        end>
      ListItemStyle = 'MetropolisUI'
      AutoBufferCount = False
      FillHeaderExpressions = <>
      FillBreakFieldName = 'ward'
      FillHeaderCustomFormat = '"Ward "+ward.text'
      FillBreakGroups = <>
    end
  end

The following simplified project that I used to reproduce the error is acting in a different way but the matter of the problem is almost the same. We need only a form with PrototypeBindSource1: TPrototypeBindSource; (generating literal and integer fields), BindingsList1: TBindingsList; ListBox1: TListBox; and Edit1: TEdit; Here is the LiveBindings link:

object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 20
Top = 5
object LinkListControlToField1: TLinkListControlToField
  Category = 'Quick Bindings'
  DataSource = PrototypeBindSource1
  FieldName = 'ContactName1'
  Control = ListBox1
  FillExpressions = <>
  AutoBufferCount = False
  FillHeaderExpressions = <>
  FillHeaderFieldName = 'UIntField1'
  FillBreakGroups = <>
end
object LinkControlToField1: TLinkControlToField
  Category = 'Quick Bindings'
  DataSource = PrototypeBindSource1
  FieldName = 'ContactName1'
  Control = Edit1
  Track = False
end

Selection of items do not correspond to the id of the selected record in the DataSource (DataSet). It seems that the LiveBindings engine synchronizes ItemIndex property of the TListBox but not the real id of the selected record. Is there any correct way out to resolve the issue?

enter image description here

1

1 Answers

0
votes

I tried to use live bindings but found that the moment you move away from the trivial into the real world that the hoops you have to jump through to make it work not worth the effort. This is a case in point, I think. While you are doing 'what they thought of' (1 item = 1 record) things are fine but once you move away from that you can no longer use quick bindings and have to start building your own custom binding classes which needs a far deeper understanding of live bindings than Quick Bindings, and in my view kinda defeats the object of the exercise.

So unless you want to stick to the simple way of doing things I don't think that there is a simple answer.

In my case I was using XE2 I am not aware of things moving on much in XE5.