In the core of LiveBindings expressions of RAD Studio XE2

WARNING! I’ve been authorized by EMBARCADERO to write about RAD Studio XE2.

RAD Studio XE2 is full of nice and exciting features. One of the most awaited of them is the LiveBindings.

The LiveBindings is available to the VCL and the new FireMonkey framework and allows to connect a property object to another using an expression and a set of observers.
Let’s say Edit1.Text “is binded to” Person1.Name also in a bidirectional way. The “link” between a property (or a group of properties) and another property can also be very complex.

The following is an example of a complex bind expression that return a value:

"This is a full name: " + Trim(ToUpperCase(FirstName)) + ", " + Trim(ToUpperCase(LastName))

I’ve waited LiveBindings for ages and now they are here!

So, let’s look a deep inside to the core of livebindings expression evaluator,
the TBindingExpression.

The TBindingExpression is an abstract class that allows to evaluate an expression. But, what’s an expression? An expression is a string that return, or not return, a value. You could see an expression as a little function or procedure.
To explain the concept, I’ve build a simple expression interpreter using an XE2 beta version.

It is very simple but shows the power of expression engine.
This is the scriptengine while evaluates a simple arithmetic expression.

The expression engine is not only a “static” evaluator. Using the powerful Delphi RTTI introduced in Delphi 2010, you can also allows the expression to “read” and “call” property and method of your Delphi objects!!

So, now, some code is needed.

As you can see, you can “register” some association between a real object and an alias in the expression. So, if my object are declared as the following:

I can use a expression as the following:

Going further, you can call methods in your expression!

So, if you have methods declared as following:

You can use the following expression:

Obviously, when you link a property to another you should not use dialogs in the expressions, but this feature is VERY powerful.
You can create different expression and use them as a custom calculator for specific business rules. The expressions are strings, so you can store them in a file or in a database and use them as needed. The expression engine is not a complete scripting language, but it can be used (and abused) in a very broad range of situations.

For complex business rules, I hate the classic chain


so I usually use a DomainModel that use datasets only to read data.

The LiveBinding allows me to use (for complex business rules) the following chain


This is only an introduction to the LiveBingind engine. ASAP I’ll post other articles about it.

I’ll talk about the livebinding engine at the ITDevCon2011 conference. Will be you there?

RAD Studio XE2 will be officially presented all over the world during the “RADStudio XE2 World Tour”.
You can find the list of all launch events in the RADStudio XE2 World Tour page.

I’ll be a presenter at 3 launch events in Italy and United Arab Emitates.
These are the events where I’ll be (click to register):

  • 19th Dubai, United Arab Emirates
  • 21nd Milan, Italy
  • 22nd Rome, Italy

Stay tuned.