绑定表达式中可以有简单的运算和字符串连接, 但字符串需放在双引号中.
还可以使用 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. 修改jar包中class文件

    某日,想要更改jar包中的某个class文件,有无rar无法解压jar文件,故找到如下方式进行操作 1.解压某个jar包:在需要解压的jar包目录下,打开命令行(cmd),输入如下命令,输入:C:\j ...

  2. Mysql where in (几百或几千个id)的优化

    1. SELECT employees.* FROM employees, clients WHERE employees.client_id = clients.id AND clients.nam ...

  3. STM32程序编写或调试犯过的错误

    1.宏定义后加了分号: eg: define NOKEY_PRES 0;      (❌) define NOKEY_PRES 0      (✔) 2.

  4. Effective C++条款05:了解C++默默编写并调用哪些函数

    class Empty{}; class Empty{ Empty(){}; Empty(const Empty& rhs){}; ~Empty(){}; Empty& operato ...

  5. C#基础知识之父子类,实例、静态成员变量,构造函数的执行顺序(经典示例)

    父子类.示例.静态成员变量.构造函数的概念的基础理解完全可以利用下面的示例诠释,非常经典,直接上代码: public class ShowInfo { public ShowInfo(string i ...

  6. python基础练习题2

    01:python九九乘法表 for i in range(1,10): for j in range(1,i+1): print('{}*{}={}'.format(j,i,i*j),end='\t ...

  7. 去掉input密码框自动补全功能

    <input name="password" autocomplete="off" hidden> <input type="pas ...

  8. canvas合并两张图片

    解析: 原理是一样的 画多张图需要一张一张画 也就是等图片onload成功后处理 这里代码写的比较随意 实际用的时候可以小粉转一下 也非常简单.我懒~~ 么么.. newImage(text) { / ...

  9. Extjs中如何在一行textfield后面增加文字提示

    添加监听事件: listeners: {               render: function(obj) {                     var font=document.cre ...

  10. Java 8 Date常用工具类

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11983108.html Demo package org.fool.util; import java ...