綁定運算式中可以有簡單的運算和字串串連, 但字串需放在雙引號中.
還可以使用 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;interfaceuses 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()