绑定表达式中可以有简单的运算和字符串连接, 但字符串需放在双引号中.
还可以使用 TBindingsList.Methods 提供的一组表达式函数(分别来自 System.Bindings.Methods 和 Data.Bind.EngExt 单元):

ToStr()
ToVariant()
Round()
Format()
UpperCase()
LowerCase()
FormatDateTime()
StrToDateTime()
Max()
Min()
CheckedState()
SelectedItem()
SelectedText()

示例: 用三个 TLabel 分别呈现窗体的宽度、高度、面积.

现在窗体上添加 Label1、Label2、Label3、BindingsList1, 并激活窗体的 OnCreate 和 OnResize 事件:


unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, Data.Bind.EngExt,
  Fmx.Bind.DBEngExt, Data.Bind.Components; type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    BindingsList1: TBindingsList;
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
  end; var
  Form1: TForm1; implementation {$R *.fmx} procedure TForm1.FormCreate(Sender: TObject);
begin
  with TBindExpression.Create(BindingsList1) do
  begin
    ControlComponent := Label1;
    ControlExpression := 'Text';
    SourceComponent := Form1;
    SourceExpression := '"宽度: " + ToStr(Width)';
    Active := True;
  end;   with TBindExpression.Create(BindingsList1) do
  begin
    ControlComponent := Label2;
    ControlExpression := 'Text';
    SourceComponent := Form1;
//    SourceExpression := '"高度: " + ToStr(Height)';
    SourceExpression := 'Format("高度: %s", ToStr(Height))'; //同上一行; 在表达式中使用 Format 函数时, 后面的参数不能放在 [] 中
    Active := True;
  end;   with TBindExpression.Create(BindingsList1) do
  begin
    ControlComponent := Label3;
    ControlExpression := 'Text';
    SourceComponent := Form1;
    SourceExpression := '"面积: " + ToStr(Width * Height)';
    Active := True;
  end;
end; procedure TForm1.FormResize(Sender: TObject);
begin
  BindingsList1.Notify(Sender, 'Width');
  BindingsList1.Notify(Sender, 'Height');
end; end.

在表达式中还可以使用关键字 Self、Owner.


参考: Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()

Delphi XE2 之 FireMonkey 入门(25) - 数据绑定: TBindingsList: 表达式的灵活性及表达式函数的更多相关文章

  1. Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件

    Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件 表达式中的函数有 ...

  2. Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope

    Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope 如果在编写表达式时, 如果能够随意指认需要的控件就好了(通过 Owne ...

  3. Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList、TBindPosition [未完成...]

    Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList.TBindPosition [未完成...] //待补...

  4. Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法

    Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法 TBindingsList 中可能不止一个表达式, 通 ...

  5. Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()

    Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText().CheckedState() 示例构想: 用 ...

  6. Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems

    Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems 如果要给一对 "源控件" 和 " ...

  7. Delphi XE2 之 FireMonkey 入门(23) - 数据绑定: TBindingsList: TBindExpression

    准备用 TBindingsList 重做上一个例子. 可以先把 TBindingsList 理解为是一组绑定表达式(TBindExpression)的集合;官方应该是提倡在设计时完成 TBindExp ...

  8. Delphi XE2 之 FireMonkey 入门(24) - 数据绑定: TBindingsList: TBindExpression.Direction

    在学习 BindingSource 属性时, 可以让两个控件互为绑定源; TBindExpression 对应的功能是 Direction 属性. 先在窗体上添加 Edit1.Edit2.Bindin ...

  9. Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库

    Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库 一.全设计时操作: 先在窗体上放置控件: DataSource1    : TDataSource; Clie ...

随机推荐

  1. spring boot 枚举使用的坑2

    上一篇说到在枚举当在controller的方法做参数时的坑,解决方法是配置了一个converter,后来想想,如果不闲每次都加一个注解麻烦的话,可以在参数前面加一个注解,添加一个解析器应该也可以解决这 ...

  2. python学习笔记(2):科学计算及数据可视化入门

    一.NumPy 1.NumPy:Numberical Python 2.高性能科学计算和数据分析的基础包 3.ndarray,多维数组(矩阵),具有矢量运算的能力,快速.节省空间 (1)ndarray ...

  3. IO同步阻塞与同步非阻塞

    BIO.NIO.AIO IO(BIO)和NIO区别:其本质就是阻塞和非阻塞的区别 阻塞概念:应用程序在获取网络数据的时候,如果网络传输数据很慢,就会一直等待,直到传输完毕为止. 非阻塞概念:应用程序直 ...

  4. Pygame播放背景音乐与音效

    1.播放背景音乐 pygame.mixer.music.load() 加载MP3格式 加入pygame.mixer.init()即可 第十一行第一个参数:播放次数(n>0),n=0时播放1次,- ...

  5. gradle上sourceSets配置&同名文件合并问题

    gradle的sourceSets可以对不同的buildType, productFlavor,buildVariant设置不同的文件路径,进行多样化处理. sourceSets{ main{ man ...

  6. Axiso解决跨域访问

    问题: 在项目中需要需要讲本地项目去请求一个URL接口获取数据 例如: 本地请求地址:http://127.0.0.1:19323/site/info.json 请求Url地址:http://www. ...

  7. Keycode含义

    keycode 是键盘上每一个按键对应的码keycode如下 :keycode 0 = keycode 1 = keycode 2 = keycode 3 = keycode 4 = keycode ...

  8. centos7安装mxnet

    pip install mxnet-cu90 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 安装sklearn时总报错 ...

  9. 计蒜客 蓝桥模拟 H. 封印之门

    Floyd算法,最短路,判断a,b是否相等. 代码: #include <cstdio> #include <cstdlib> #include <cstring> ...

  10. [人工智能]IBM Watson人工智能API|一步步创建智能微信翻译官|第一章

    最近参加了IBM可认知内部创业活动,想从零创建一个微信翻译工具,这就是我的AI翻译官.