在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函数)的更多相关文章

  1. AngularJS中数据双向绑定(two-way data-binding)

    1.切换工作目录 git checkout step-4 #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-m ...

  2. React中的“双向绑定”

    概述 React并不是一个MVVM框架,其实它连一个框架都算不上,它只是一个库,但是react生态系统中的flux却是一个MVVM框架,所以我研究了一下flux官方实现中的"双向绑定&quo ...

  3. vue中数据双向绑定注意点

    最近一个vue和element的项目中遇到了一个问题: 动态生成的对象进行双向绑定是失败 直接贴代码: <el-form :model="addClass" :rules=& ...

  4. vue中数据双向绑定的实现原理

    vue中最常见的属v-model这个数据双向绑定了,很好奇它是如何实现的呢?尝试着用原生的JS去实现一下. 首先大致学习了解下Object.defineProperty()这个东东吧! * Objec ...

  5. javascript中的双向绑定

    阅读目录 一:发布订阅模式实现数据双向绑定 二:使用Object.defineProperty 来实现简单的双向绑定. 前言: 双向数据绑定的含义:可以将对象的属性绑定到UI,具体的说,我们有一个对象 ...

  6. vue中的双向绑定

    概述 今天对双向绑定感兴趣了,于是去查了下相关文章,发现有用脏检查的(angular.js),有用发布者-订阅者模式的(JQuery),也有用Object.defineProperty的(vue),其 ...

  7. wp中的双向绑定

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...

  8. 利用JS实现vue中的双向绑定

    Vue 已经是主流框架了 它的好处也不用多说,都已经是大家公认的了 那我们就来理解一下Vue的单向数据绑定和双向数据绑定 然后再使用JS来实现Vue的双向数据绑定 单向数据绑定 指的是我们先把模板写好 ...

  9. AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4

    1.切换工作目录 git checkout step- #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-mo ...

随机推荐

  1. Struts2配置问题java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    方法一:右键点击项目--->build path-->configure build path-->左侧菜单栏就会看到Deployment Assembly-->右侧点击add ...

  2. 创建、更新、删除文档。 --- Mongodb权威指南阅读。

    插入文档: db.foo.insert({ "key" : "value"}); 使用insert插入一个数据,文档中如果没有_id 会自动给文档增加_id. ...

  3. leetcode Valid Parentheses python

    # 解题思路: # 创建一个字典映射关系 dicts# 使用一个栈stk 遍历字符串s 得到一个新的字符串curItem 如果lastItem在dicts中的value和它相等 不做任何操作# 如果不 ...

  4. javaEE简答题整理

    1. 什么是JavaEE?其编程思想是什么? JavaEE是一个标准的中间件体系结构,是企业分布式应用开发标准.JavaEE的编程思想是组件—容器. 2. 为什么提出JavaEE体系结构? (1)为满 ...

  5. Werkzeug源码阅读笔记(三)

    这次主要讲下werkzeug中的Local. 源码在werkzeug/local.py Thread Local 在Python中,状态是保存在对象中.Thread Local是一种特殊的对象,它是对 ...

  6. #pragma anon_unions, #pragma no_anon_unions

    #pragma anon_unions, #pragma no_anon_unions 这些编译指示启用和禁用对匿名结构和联合的支持. 缺省设置 缺省值为 #pragma no_anon_unions ...

  7. 柯南君:看大数据时代下的IT架构(6)消息队列之RabbitMQ--案例(Publish/Subscribe起航)

    二.Publish/Subscribe(发布/订阅)(using the Java Client) 为了说明这个模式,我们将构建一个简单的日志系统.它将包括两个项目: 第一个将发出日志消息 第二个将接 ...

  8. MapReduce实现矩阵相乘

    矩阵相乘能够查看百度百科的解释http://baike.baidu.com/view/2455255.htm?fr=aladdin 有a和b两个矩阵 a:                1   2   ...

  9. js实现页面时钟

    <body onload="setInterval(nowtime,1000)">    <form id="main" method=&qu ...

  10. 基于Jquery的Ajax分页,只有上一页和下一页

    最近项目中用到ajax分页 在网上找到一个非常好用的分页插件jquery-pagination-ajax,以下是链接 http://www.zhangxinxu.com/wordpress/2010/ ...