我正在使用Delphi XE2编写VCL win32应用程序。 Delphi XE2支持实时绑定(bind)。我将示例Biolife.xml加载到TClientDataSet实例中。

我能够将TEdit控件绑定(bind)到数据集的字符串字段:种名:

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

然后,我尝试将Graphic字段绑定(bind)到TImage控件:
object BindLinkImage11: TBindLink
  Category = 'Links'
  SourceMemberName = 'Graphic'
  ControlComponent = Image1
  SourceComponent = BindScopeDB1
  ParseExpressions = <>
  FormatExpressions = <
    item
      ControlExpression = 'Picture'
      SourceExpression = 'Value'
    end>
  ClearExpressions = <>
end

显然,它不起作用。有可能这样做吗?

最佳答案

看一看BindLinkVCLProject演示项目。还显示了图像的绑定(bind),因此我想您需要以这种方式进行操作(Self中的SourceExpression表示一个blob字段):

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

10-07 19:03
查看更多