Search code examples
delphilivebindings

Why can't I do LiveBinding against a data module in XE5?


I have a FireMonkey Mobile app which I had working with a TSQlConnection and a TSQLDataset on the actual form. The dataset was populating a TComboBox with no problems but then I decided I would put all of my Database code etc into a DataModule.

Move the TSqlConnection and data source across and add the Datamodul. Checked to make sure it all works and is open without problems. I then remove the original components from the form and remove the bindings completely. Redo the bindings so that they use the data stuff from the datamodule. Build the app and go the correct form... Nothing in the combobox.

Attached events on the open etc of the datasets and they are all open and okay. Even fires the FilledList event on the bindings... So why do they not appear when they used to?

Code for Combobox

object itemModel: TListBoxItem [1]
  Height = 44.000000000000000000
  Position.Y = 44.000000000000000000
  StyleLookup = 'listboxitemnodetail'
  Width = 384.000000000000000000
  object cboModel: TComboBox
    Align = alClient
    DisableFocusEffect = False
    Height = 32.000000000000000000
    TabOrder = 0
    Width = 384.000000000000000000
  end
end

Code for the Datasource

 object BindSourceDB2: TBindSourceDB
    DataSet = dmdLocal.dsModels
    ScopeMappings = <>
    Left = 176
    Top = 272
  end

Code for the link fill

object LinkFillControlToField2: TLinkFillControlToField
  Category = 'Quick Bindings'
  Control = cboModel
  Track = True
  FillDataSource = BindSourceDB2
  FillDisplayFieldName = 'MODEL'
  AutoFill = True
  BufferCount = -1
  AutoBufferCount = False
  FillExpressions = <>
  FillHeaderExpressions = <>
  FillBreakGroups = <>
end

Edited to add the code


Solution

  • You need to ensure that your data module is created before your form. This is so when the form is opened, there's an instance (in this case) of dmdLocal which in turn has an instance of the datasource you're after - in this case dsModels. Otherwise you could assign the property at runtime once you know your datamodule has been created.