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 ...
随机推荐
- ftp上来显示的时间和系统时间不一致
ftp上来显示的时间和系统时间不一致,是因为默认情况下,vsftpd 是用GMT做为他的时间的,所以和系统的时间可能会不一致 修改也非常简单: vi /etc/vsftpd/vsftpd.conf 在 ...
- C++_内部类
C++ 内部类和外部类之间的相互调用
- C语言处理CSV文件的方法(二)
strtok函数的使用是一个老生常谈的问题了.该函数的作用很大,争议也很大.以下的表述可能与一些资料有区别或者说与你原来的认识有差异,因此,我尽量以实验为证.交代一下实验环境是必要的,win7+vc6 ...
- prob5 of 140
#include<stdio.h>int main(){ int n,i=1,j=1; double s=1,s1=0;; //scanf("%d",&n); ...
- mysql集群安装配置
看网上很多人说mysql集群不是很稳定,因此这2天做了下mysql的集群,打算配置没有什么问题了,过2天做下相关的性能测试,我的配置环境如下: 操作系统: Centos5.2 软件 ...
- <s:if>标签与ActionContext.getContext().getSession()
今天在做<s:if>标签中的属性值从 ActionContext.getContext().getSession().put("WW_TRANS_I18N_LOCALE" ...
- Centos for php+mysql+apache
一.安装 MySQL 首先来进行 MySQL 的安装.打开超级终端,输入: [root@localhost ~]# yum install mysql mysql-server 安装完毕,让 MySQ ...
- how to install git 1.8 rpm
git版本在低于1.8之前,对于私有项目会出现401的pull失败错误,只能通过升级git版本来解决 It appears that git18 is no longer available from ...
- JavaWeb基础之tomcat部署
有些东西,看起来简单,做起来也简单,简单的你并不一定知道! 问题:如何将一个java project转变为 web project,并使其自动部署到tomcat? 1.先建立一个Java Projec ...
- 几个DOM属性
1,childNodes,包含这个元素全部子元素的数组: 2,nodeType, 元素节点的nodeType属性值是1: 属性节点............................2: 文本 ...