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 ...
随机推荐
- php配置伪静态如何将.htaccess文件转换 nginx伪静态文件
php通常设置伪静态三种情况,.htaccess文件,nginx伪静态文件,Web.Config文件得形式,如何将三种伪静态应用到项目中呢, 1,.htaccess文件 实例 <IfModule ...
- 利用AXI-DMA批量发送数据到DMA
1.1 主函数 int main(void) { XGpio_Initialize(&Gpio, AXI_GPIO_DEV_ID); XGpio_SetDataDirection(&G ...
- luogu P5338 [TJOI2019]甲苯先生的滚榜
传送门 首先,排名系统,一看就知道是原题,可以上平衡树来维护 然后考虑一种比较朴素的想法,因为我们要知道排名在一个人前面的人数,也就是AC数比他多的人数+AC数一样并且罚时少的人数,所以考虑维护那两个 ...
- egretios包接微信/facebook登录
ios包有了,现在需要登录,就先使用微信登录吧,后继加一个facebook登录. 根据我的理解,先预测一下应该是怎么回事吧. 首先应该是要去微信的公共平台注册一下,说我的应用是什么应用,要填写企业信息 ...
- ls, dir, vdir - 列目录内容
ls [选项] [文件名...] POSIX 标准选项: [-CFRacdilqrtu1] GNU 选项 (短格式): [-1abcdfgiklmnopqrstuxABCDFGLNQRSUX] [-w ...
- CentOS7 添加新用户并授权 root 权限
参考文章:CentOS 7中添加一个新用户并授权 # root 用户操作 $ 普通用户操作 创建用户 # adduser USERNAME # passwd USERNAME (输入密码) 授权 ro ...
- 021-制作OpenStack镜像官方文档
可参考官方文档:https://docs.openstack.org/image-guide/ 制作centos7 :https://docs.openstack.org/image-guide/ce ...
- Linux服务器安装系统之1-LSI阵列卡Raid10配置方法
- web页面调用app的方法
use_app_goto_page: (skip_type, skip_target) => { // Android App if (/android/i.test(navigator.use ...
- 【leetcode】560. Subarray Sum Equals K
题目如下:解题思路:本题的关键在于题目限定了是连续的数组,我们用一个dp数组保存第i位到数组末位的和.例如nums = [1,1,1],那么dp = [3,2,1], dp[i]表示nums[i]+n ...