zoukankan      html  css  js  c++  java
  • Delphi XE2 之 FireMonkey 入门(28) 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()


    示例构想: 用 Label1 显示 ListBox1 的选项, 用 Label2 显示 CheckBox1 的状态.

    1、放控件: Label1、Label2、ListBox1、CheckBox1、BindingsList1、BindScope1;
    2、激活 ListBox1 的 OnClick 事件和窗体的默认事件.

    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, FMX.Layouts, FMX.ListBox;
    
    type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        ListBox1: TListBox;
        CheckBox1: TCheckBox;
        BindingsList1: TBindingsList;
        BindScope1: TBindScope;
        procedure FormCreate(Sender: TObject);
        procedure ListBox1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.fmx}
    
    uses Fmx.Bind.Editors; //使用表达式函数 SelectedText、SelectedItem、CheckedState 时, 需要的支持单元
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 1 to 9 do
        ListBox1.Items.Add('Item_' + IntToStr(i));
    
      with TBindExpression.Create(BindingsList1) do
      begin
        ControlComponent := Label1;
        ControlExpression := 'Text';
        SourceComponent := BindScope1;
        SourceExpression := 'SelectedText(ListBox1)';   //同下一行
    //    SourceExpression := 'ListBox1.Selected.Text';
        Active := True;
      end;
    
      with TBindExpression.Create(BindingsList1) do
      begin
        ControlComponent := Label2;
        ControlExpression := 'Text';
        SourceComponent := BindScope1;
        SourceExpression := 'CheckedState(CheckBox1)'; //Checked: 'True'; Unchecked: 'False'; Grayed: ''
    //    SourceExpression := 'CheckBox1.IsChecked';   //在本例中, 这等同于上一行
        Active := True;
      end;
    
      CheckBox1.OnClick := ListBox1.OnClick;
    end;
    
    procedure TForm1.ListBox1Click(Sender: TObject);
    begin
      BindingsList1.Notify(Sender, '');
    end;
    
    end.
    

  • 相关阅读:
    php上传文件大小限制
    phpStudy for Linux (lnmp+lamp一键安装包)
    linux 常见问题
    Cmake设置环境变量
    NSIS Installer(被NSI脚本编译出来的target)获取命令行参数
    VS2010 Command Prompt Error:Cannot determine the location of the VS Common Tools folder
    关于老驱动不能在windows 8下正常安装的问题
    去除安装程序的窗口显示(类似于后台安装)
    NSIS操作系统环境变量
    NSIS检测操作系统x64还是x86的问题。
  • 原文地址:https://www.cnblogs.com/del/p/2198434.html
Copyright © 2011-2022 走看看