zoukankan      html  css  js  c++  java
  • Delphi XE2 之 FireMonkey 入门(24) 数据绑定: TBindingsList: TBindExpression.Direction


    在学习 BindingSource 属性时, 可以让两个控件互为绑定源; TBindExpression 对应的功能是 Direction 属性.

    先在窗体上添加 Edit1、Edit2、BindingsList1; 然后激活 Edit1、Edit2 和窗体的默认事件.

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TBindExpression.Create(BindingsList1) do
      begin
        ControlComponent := Edit2;
        ControlExpression := 'Text';
        SourceComponent := Edit1;
        SourceExpression := 'Text';
    //    Direction := TExpressionDirection.dirSourceToControl; //默认
    //    Direction := TExpressionDirection.dirControlToSource; //反向
        Direction := TExpressionDirection.dirBidirectional;     //双向
        Active := True;
      end;
    end;
    
    procedure TForm1.Edit1Change(Sender: TObject);
    begin
      BindingsList1.Notify(Sender, '');
    end;
    
    procedure TForm1.Edit2Change(Sender: TObject);
    begin
      BindingsList1.Notify(Sender, '');
    end;
    


    如果没有 Direction 属性, 代码或许会是:

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TBindExpression.Create(BindingsList1) do
      begin
        ControlComponent := Edit2;
        ControlExpression := 'Text';
        SourceComponent := Edit1;
        SourceExpression := 'Text';
        Active := True;
      end;
    
      with TBindExpression.Create(BindingsList1) do
      begin
        ControlComponent := Edit1;
        ControlExpression := 'Text';
        SourceComponent := Edit2;
        SourceExpression := 'Text';
        Active := True;
      end;
    end;
    
    procedure TForm1.Edit1Change(Sender: TObject);
    begin
      BindingsList1.Notify(Sender, '');
    end;
    
    procedure TForm1.Edit2Change(Sender: TObject);
    begin
      BindingsList1.Notify(Sender, '');
    end;
    

  • 相关阅读:
    【LeetCode】96.Unique Binary Search Trees
    【LeetCode】136.Single Number
    VirtualBox下Linux加载Windows的共享目录
    Macbook上Windows的触摸板设置工具
    [转]太岁三煞五黄
    [转]UI、GUI、UE、UX、ID、UED、UCD的区别
    紫微斗数:命主和身主
    [转]如何降低二手烟的危害
    [转]从第六十三卦到第六十四卦
    Mac显示和隐藏隐藏文件
  • 原文地址:https://www.cnblogs.com/del/p/2197989.html
Copyright © 2011-2022 走看看