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 ...
随机推荐
- 异常 ORA-00257: archiver error. Connect internal only, until freed
我oracle 是安装在linux 下. ORA-00257: archiver error. Connect internal only, until freed 得知是错误是由于归档日志(arch ...
- jQuery 1.9不支持$.browser 怎么判断浏览器类型和版本
$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());$.browser.webkit = /webkit/.te ...
- Javascript 学习笔记 无缝滚动
效果 : 鼠标移入图片 停止滚动, 鼠标移出自动滚动 可以调整向左或右方向滚动 <style type="text/css"> * { margin:; padding ...
- windows下载安装requests
1.下载地址:https://github.com/kennethreitz/requests 2.解压缩后,cd requests 3.安装 python setup.py install
- Lucky Sum
Description Lucky Sum time limit per test: 2 seconds memory limit per test: 256 megabytes input: sta ...
- 安装solaris_11.2与windows双系统(VM10模拟实现)(一)
感慨:这周刚接触solaris,装solaris很蛋疼,一个字:慢! 在上面安装软件包依然很慢,无线网也很不稳定. 在上面搭建环境更蛋疼,一个字:惨! 什么环境之类的废话就不多说了,一般的电脑都可以. ...
- CentOS rc.local 不执行的问题
centos7 开机/etc/rc.local 不执行的问题 时间:2015-02-09 00:54来源:blog.51cto.com 作者:“闲潭小筑” 博客, 举报 点击:次 最近发现centos ...
- Sql Server数据库快照初探
什么是快照 数据库快照是 SQL Server 数据库(源数据库)的只读静态视图.换句话说,快照可以理解为一个只读的数据库.利用快照,可以提供如下好处: 提供了一个静态的视图来为报表提供服务 可以利用 ...
- 解密电子书之四:MCU(freescale)
谈完国产的君正,让我们再看看呛了君正财路的freescale iMX51. 这是freescale近期的主打产品,用的是ARM Cortex A8架构,主频在消费电子领域最高可达800MHz,在工业领 ...
- 如何評鑑一家SMT代工廠
我們一般稱專業的「電子代工廠」為 EMS(Electronics Manufacturing Service,電子製造服務業) 或 CM(Contract Manufacturer,合同製造廠),這些 ...