Delphi XE2 之 FireMonkey 入门(25) - 数据绑定: TBindingsList: 表达式的灵活性及表达式函数
还可以使用 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: 表达式的灵活性及表达式函数的更多相关文章
- Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件
Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件 表达式中的函数有 ...
- Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope
Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope 如果在编写表达式时, 如果能够随意指认需要的控件就好了(通过 Owne ...
- Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList、TBindPosition [未完成...]
Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList.TBindPosition [未完成...] //待补...
- Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法
Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法 TBindingsList 中可能不止一个表达式, 通 ...
- Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()
Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText().CheckedState() 示例构想: 用 ...
- Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems
Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems 如果要给一对 "源控件" 和 " ...
- Delphi XE2 之 FireMonkey 入门(23) - 数据绑定: TBindingsList: TBindExpression
准备用 TBindingsList 重做上一个例子. 可以先把 TBindingsList 理解为是一组绑定表达式(TBindExpression)的集合;官方应该是提倡在设计时完成 TBindExp ...
- Delphi XE2 之 FireMonkey 入门(24) - 数据绑定: TBindingsList: TBindExpression.Direction
在学习 BindingSource 属性时, 可以让两个控件互为绑定源; TBindExpression 对应的功能是 Direction 属性. 先在窗体上添加 Edit1.Edit2.Bindin ...
- Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库
Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库 一.全设计时操作: 先在窗体上放置控件: DataSource1 : TDataSource; Clie ...
随机推荐
- http请求响应丢包问题
在与合作方联调某个明细数据接口的时候发现 1.当请求条数为4,content-length<1500时,数据可以正确返回. 2.当请求条数为5,content-length>1500时,无 ...
- php编译完成后,module追加编译进php
# 如果在编译的时候忘记添加某些模块,可以使用这种办法来重新编译添加! # 首先,进入PHP目录(未编译)的扩展目录 cd /home/soft/php-5.2.14/ext/ftp/ # 调用php ...
- [51Nod1623] 完美消除
link $solution:$ 首先我们可以发现一个结论,对于一个数 $x$ ,它的最低修改次数为它每位与前去中是否都比此位上的数大,有则答案 $-1$ .因为若有小数则没有办法将其答案贡献变低. ...
- P2586 [ZJOI2008]杀蚂蚁
传送门 快乐模拟,修身养性 代码长度其实还好,主要是细节多 只要知道一些计算几何基础知识即可快乐模拟,按着题目要求一步步实现就行啦 注意仔细读题,蚂蚁每 $5$ 秒乱走一次的时候是只要能走就走了,不一 ...
- python查询mysql中是否存在某张表(传参)
客户端输入了表的名字,服务端判断表是否存在. 参考:https://blog.csdn.net/qq_36523839/article/details/80639297 需要导入re模块: impor ...
- 自定义UICollectionViewLayout
UICollectionView在iOS6中第一次被介绍,也是UIKit视图类中的一颗新星.它和UITableView共享API设计,但也在UITableView上做了一些扩展.UICollectio ...
- Spring基础09——Bean的自动装配
1.XML配置的Bean自动装配 SpringIOC容器可以自动装配Bean,需要做的仅仅是在<bean>的autowire属性里指定自动装配的模式,而不需要手工去指定要装配的Bean,a ...
- 个人作业 项目alpha版本测试
课程:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业要求:https://edu.cnblogs.com/campus ...
- 服务器上搭建jupyter notebook
参考:https://zhuanlan.zhihu.com/p/44405596 https://blog.csdn.net/cvMat/article/details/79351420 遇到的问题 ...
- Codeforces 912 质因数折半 方格数学期望
A B #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #d ...