TBindingsList 中可能不止一个表达式, 通过表达式的 Evaluate 方法可单独提交绑定, 并可在 Active = False 时提交.
在 TBindExprItems 中对应的方法是 EvaluateFormat.

测试设想: Label1、Label2 的绑定源同是 Edit1, 分别提交绑定.

1、在窗体上加控件: Label1、Label2、Edit1、BindingsList1;
2、激活 Edit1 的 OnKeyUp、OnChange 事件, 还有窗体的默认事件.

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Edit, Data.Bind.EngExt,
  FMX.Bind.DBEngExt, Data.Bind.Components;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    BindingsList1: TBindingsList;
    procedure FormCreate(Sender: TObject);
    procedure Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
    procedure Edit1Change(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

var
  bindExpression1, bindExpression2: TBindExpression;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bindExpression1 := TBindExpression.Create(BindingsList1);
  bindExpression2 := TBindExpression.Create(BindingsList1);

  with bindExpression1 do
  begin
    ControlComponent := Label1;
    ControlExpression := 'Text';
    SourceComponent := Edit1;
    SourceExpression := 'Text';
    // Active := True;
  end;

  with bindExpression2 do
  begin
    ControlComponent := Label2;
    ControlExpression := 'Text';
    SourceComponent := Edit1;
    SourceExpression := 'UpperCase(Text)';
    // Active := True;
  end;
end;

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  bindExpression1.Evaluate;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  bindExpression2.Evaluate;
end;

end.

posted on 2011-10-03 12:51  万一  阅读(3351)  评论(0编辑  收藏  举报