DelphiXe5中的双向绑定(使用使用TBindScope和TBindExpression,并覆盖AfterConstruction函数)
在Delphi下等这一功能很久了,虽然C#下早已实现了这一功能。但是在Dephi下尝试这项功能时还是有些许的激动。闲言少絮,直接上代码。
unit BindingDemo; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.Bind.EngExt, Vcl.Bind.DBEngExt,
Vcl.StdCtrls, Data.Bind.Components, Vcl.Grids; type
TPerson = class(TObject)
protected
fName: string;
fAge: integer;
procedure
SetName(const Value: string);
public
property Name: string read fName write SetName;
property Age: integer read fAge write fAge;
end; type
/// <summary>
/// 一个object与ui控件绑定的简单例子
/// </summary>
TForm2 = class(TForm)
bndscp1: TBindScope;
bndngslst1: TBindingsList;
Button1: TButton;
Button2: TButton;
edt1: TEdit;
procedure btnLoadClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
fInitialized: boolean;
fPerson: TPerson;
procedure Initialize;
{ Private declarations }
public
{ Public declarations }
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
end; var
Form2: TForm2; implementation {$R *.dfm} procedure TForm2.AfterConstruction;
begin
inherited;
Initialize;
end; procedure TForm2.BeforeDestruction;
begin
fPerson.Free;
inherited;
end; procedure TForm2.btnLoadClick(Sender: TObject);
begin
fPerson.Name := 'Doogie Howser';
fPerson.Age := ;
bndscp1.DataObject := fPerson;
end; procedure TForm2.btnSaveClick(Sender: TObject);
begin
bndngslst1.Notify(edt1, '');
end; procedure TForm2.Initialize;
var
expression: TBindExpression;
begin
//Create a binding expression.
expression := TBindExpression.Create(self);
expression.ControlComponent := edt1;
expression.ControlExpression := 'Text';
//The Text property of Edit1 ...
expression.SourceComponent := bndscp1;
expression.SourceExpression := 'Name';
//... is bound to the Name property of fPerson
expression.Direction := TExpressionDirection.dirBidirectional;
//Add the expression to the bindings list.
expression.BindingsList := bndngslst1;
//Create a Person object.
fPerson := TPerson.Create;
end; { TPerson } procedure TPerson.SetName(const Value: string);
begin
fName := Value;
//ShowMessage('Name changed to "'+ Value +'"');
end; end.
http://blog.csdn.net/diligentcatrich/article/details/24552151
DelphiXe5中的双向绑定(使用使用TBindScope和TBindExpression,并覆盖AfterConstruction函数)的更多相关文章
- AngularJS中数据双向绑定(two-way data-binding)
1.切换工作目录 git checkout step-4 #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-m ...
- React中的“双向绑定”
概述 React并不是一个MVVM框架,其实它连一个框架都算不上,它只是一个库,但是react生态系统中的flux却是一个MVVM框架,所以我研究了一下flux官方实现中的"双向绑定&quo ...
- vue中数据双向绑定注意点
最近一个vue和element的项目中遇到了一个问题: 动态生成的对象进行双向绑定是失败 直接贴代码: <el-form :model="addClass" :rules=& ...
- vue中数据双向绑定的实现原理
vue中最常见的属v-model这个数据双向绑定了,很好奇它是如何实现的呢?尝试着用原生的JS去实现一下. 首先大致学习了解下Object.defineProperty()这个东东吧! * Objec ...
- javascript中的双向绑定
阅读目录 一:发布订阅模式实现数据双向绑定 二:使用Object.defineProperty 来实现简单的双向绑定. 前言: 双向数据绑定的含义:可以将对象的属性绑定到UI,具体的说,我们有一个对象 ...
- vue中的双向绑定
概述 今天对双向绑定感兴趣了,于是去查了下相关文章,发现有用脏检查的(angular.js),有用发布者-订阅者模式的(JQuery),也有用Object.defineProperty的(vue),其 ...
- wp中的双向绑定
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...
- 利用JS实现vue中的双向绑定
Vue 已经是主流框架了 它的好处也不用多说,都已经是大家公认的了 那我们就来理解一下Vue的单向数据绑定和双向数据绑定 然后再使用JS来实现Vue的双向数据绑定 单向数据绑定 指的是我们先把模板写好 ...
- AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4
1.切换工作目录 git checkout step- #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-mo ...
随机推荐
- Java SE基础部分——常用类库之Math和Random类(随机产生数值)
//20160518 Math类常用方法 练习 package MyPackage; public class MathDemo {//定义主类和main方法 public static void m ...
- 64位ubuntu编译32位程序
最近在64位ubuntu上开发,需要编译32位程序,需要安装这两个包,然后在编译器参数加上-m32.不放心的话可以用ldd或file查看一下是否生成了对应位数的程序. $ apt-get inst ...
- leetcode Count and Say python
class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str " ...
- Linux学习之(())操作符
在刚开始学习inux shell脚本编程时候,对于它的 四则运算以及逻辑运算.估计很多朋友都感觉比较难以接受.特变逻辑运算符”[]”使用时候,必须保证运算符与算数 之间有空格. 四则运算也只能借助:l ...
- artdialog关闭弹出窗口
打开 function opentree(){ var dialog = art.dialog({ title: '选择提交部门', content:jQuery("#my ...
- 加载loading的ajax写法
ajaxStart()与ajaxStop():当Ajax请求开始时,会触发ajaxStart()方法的回调函数.当Ajax请求结束时,会触发ajaxStop()方法的回调函数.这些方法都是全局的方法, ...
- saiku导出excel单元格格式与中文列宽自动适应
在saiku导出excel后打开发现单元格的整数也显示为小数,并且含有中文的列宽没有自动适应,解决办法如下: 打开ExcelWorksheetBuilder.java文件,找到applyCellFor ...
- mac文件权限
如何设置文件/或文件夹权限为777 进入终端,切换到指定目录,输入以下命令,后面添加你的文件名/目录名$sudo chmod -R 777 (文件名/目录名) 或 $chmod 777 ./test. ...
- [基础]RHEL6下iSCSI客户端挂载配置
本文根据鸟哥私房菜进行操作:http://linux.vbird.org/linux_enterprise/xen.php?thisscreen=800x600 一.侦测 [root@vhost3 ~ ...
- CXF 的IP拦截
非常久没有写技术文档了,今天 记录下Webserver的Ip限制吧 需求是:webserver接口能在内网訪问,可是測试平台的webserver要能够在外网訪问,这样就有了一点差别, 这个实现的比較简 ...