Search code examples
delphidelphi-xe2livebindings

How to use live binding to bind blob field to TImage control?


I am using Delphi XE2 to write a VCL win32 application. Delphi XE2 support live binding. I load sample Biolife.xml into a TClientDataSet instance.

I able to bind a TEdit control to dataset's string field: Species Name:

object BindLinkEdit11: TBindLink
  Category = 'Links'
  SourceMemberName = 'Species Name'
  ControlComponent = Edit1
  SourceComponent = BindScopeDB1
  ParseExpressions = <>
  FormatExpressions = <
    item
      ControlExpression = 'Text'
      SourceExpression = 'DisplayText'
    end>
  ClearExpressions = <>
end

I then trying to bind Graphic field to TImage control:

object BindLinkImage11: TBindLink
  Category = 'Links'
  SourceMemberName = 'Graphic'
  ControlComponent = Image1
  SourceComponent = BindScopeDB1
  ParseExpressions = <>
  FormatExpressions = <
    item
      ControlExpression = 'Picture'
      SourceExpression = 'Value'
    end>
  ClearExpressions = <>
end

Apparently, it doesn't work. Is that possible to do so?


Solution

  • Take a look into the BindLinkVCLProject demo project. There is shown also a binding for the image, so my guess is you need to do it this way (the Self in SourceExpression represents a blob field):

    object BindLinkImageHandler: TBindLink
      Category = 'Links'
      SourceMemberName = 'Graphic'
      ControlComponent = Image1
      SourceComponent = BindScopeDB1
      ParseExpressions = <
        item
          ControlExpression = 'Picture'
          SourceExpression = 'Self'
        end>
      FormatExpressions = <
        item
          ControlExpression = 'Picture'
          SourceExpression = 'Self'
        end>
      ClearExpressions = <
        item
          ControlExpression = 'Picture'
          SourceExpression = 'nil'
        end>
    end