.NET databinding in Delphi for Win32

Databinding is defined as: “General technique that binds two data/information sources together and maintains them in sync. This is usually done with two data/information sources with different types as in XML data binding. However in UI data binding, we bind data and information objects of the same type together (e.g. Java objects to Java UI elements).”

Databinding is common technique in VCL. Since Delphi 1 we have TDataset class for bind data and UI controls (DB Aware) in a GUI application.

In .NET world, instead, databinding is very different.

So, I’m starting to write (actually for fun) a DataBinder component to use .NET “like” databinding (or something similar to) in Delphi for Win32 too.

All the code has been written in about 2 hours.

TDataBinder

With this component you can “bind” an object property to another object property in a declarative mode.

e.g.

DataBinder.Add(Person, 'FirstName', Edit1, 'Text');

and then, every update to Person.FirstName property, will be reflected in the Edit1.Text property.

You can bind different control properties to different BO properties.

e.g.

//Text = FirstName
DataBinder.Add(Person, 'FirstName', Edit1, 'Text');
//If Person is not married, TEdit become flat
DataBinder.Add(Person, 'IsMarried', Edit1, 'Ctl3D');

So in your initialization code (e.g. FormCreate) you can write somethig similat to following:

procedure TForm3.FormCreate(Sender: TObject);
var
binder: TDataBinder;
begin
//Create your "BO"
Person := TPerson.Create;
//read data from "database"
Person.Load;

//Setup databinding...
binder := TDataBinder.Create(self);
binder.Add(Person, 'FirstName'   ,      Edit1,     'Text');
binder.Add(Person, 'LastName',          Edit2,     'Text');

//The same attribute binded to 3 controls
binder.Add(Person, 'Married',     CheckBox1, 'Checked');
binder.Add(Person, 'Married'   , Edit1,     'Ctl3D');
binder.Add(Person, 'Married',     Edit2,     'Ctl3D');

//The same attribute binded to 2 controls
binder.Add(Person, 'SomeInteger', ComboBox1, 'ItemIndex');
binder.Add(Person, 'SomeInteger',     TrackBar1, 'Position');

//A derived property
binder.Add(Person, 'FullName',     Panel1, 'Caption');

//let start...
binder.Bind;
end;

Other info asap so, stay tuned.

Download Code and compiled sample

(Source code require Delphi 2009)

Value Object vs Data Transfer Object

One of the main goals of design patterns is to have a names dictionary shared among professionals.
This dictionary, sometimes, has some trouble.

It’s the case of two well known design patterns: Value Object and Data Transfer Object.

Value Object, according to Martin Fowler, is defined as:
“A small simple object, like money or a date range, whose equality isn’t based on identity.”

But Value Object, according to SUN, was for some time defined as follows: “An object that carries data between processes in order to reduce the number of method calls.”

In the words of Fowler: “Many people in the Sun community use the term “Value Object” for this pattern. I use it to mean something else.” (Talking about Data Transfer Object)

Some time ago, Value Object pattern (SUN version), has been renamed to “Transfer Object” according to Fowler.

Question is exposed in a few lines by Fowler at following address: http://martinfowler.com/bliki/ValueObject.html

New home for my blog

Hi all,

now there is another home for my blog, my software, my photos and so on.

I will transfer all of my contents from the old site to this one in an reasonably short time.

English is not my natural language, so I’m apologize for any mistake you will find in these pages.

Enjoy

–Daniele Teti