zoukankan      html  css  js  c++  java
  • Delphi XE2 之 FireMonkey 入门(24)


    在学习 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;
  • 相关阅读:
    js修改div标签中的内容
    echarts如何显示在页面上
    mybatis提取<where><if>共用代码
    部署LAMP-LAMP平台集成
    PHP安装指南
    部署LAMP-mysql 安装
    apache虚拟主机
    apache默认网站
    HDU 5375 Gray code 格雷码(水题)
    HDU 5371 Hotaru's problem (Manacher,回文串)
  • 原文地址:https://www.cnblogs.com/dzdd/p/3346857.html
Copyright © 2011-2022 走看看