Skeeze - Pixabay



In SmartBinding #2 I presented the new autobinding features, which made it easy to define bindings directly in the form designer.

However why stop there? There are more cool things to put into kbmMW SmartBind. The next version of SmartBind will contain additional features for binding to cells, rows or columns in grids, multivalue expression binding and binding simple constants.

Cell, row and column binding a grid

What makes kbmMW’s “Smart” features smart, is that they focus on removing all the boilerplate code, making it easy to focus on the actual functional requirements. Doing SmartBinding by code is very easy… but it can be made even easier, which the following demo will show.

Column binding:

This is the same as shown in Smartbinding #2, but is included for completeness.

Row binding:

This is new and will be included in next kbmMW release.

Clicking Next and Prev will scroll horizontally thru the values.

Cell binding:

This is also new,

It simply binds values to specific cells in a grid.

When run:

The binding for Edit5 and Edit6 are twoway, hence typing in the editbox results in updating the cell, and typing in the cell results in updating the editbox. In addition it demos using the exprToDest expression, augmenting the data before updating the cell.

Multivalue expression binding

This is a fairly advanced one way binding, which is able to pick up data from multiple places and do all sorts of calculations or manipulations with the data and enter the result in the defined destination.

One simple way to illustrate this powerful feature, is to have a couple of edit boxes which we want to sum into a label:

At runtime it will show this:

Because that’s the only logical value to get out of the expression. But lets type some numerical values in Edit8 and Edit9:

Now we have a simple calculator all defined at designtime.

However lets take it to the next step which is to make a simple spreadsheet using a regular TStringGrid:

This time I have entered the bindings in a memo for illustrative purposes.

The actual binding is here:

{ const:"base", to:StringGrid4.#0.0 }, 
{ const:"out", to:StringGrid4.#0.1 }, 
{ const:"post", to:StringGrid4.#0.2 }, 
{ const:"cotis", to:StringGrid4.#0.3 }, 
{ const:"salaire improsable", to:StringGrid4.#0.4 }, 
{ const:"18000", to:StringGrid4.#1.0 }, 
{ expr:$[StringGrid4.#1.0]*0.05, to:StringGrid4.#1.1 } 
{ expr:$[StringGrid4.#1.0]+$[StringGrid4.#1.1], to:StringGrid4.#1.2 } 
{ expr:$[StringGrid4.#1.2]*0.09, to:StringGrid4.#1.3 } 
{ expr:$[StringGrid4.#1.2]-$[StringGrid4.#1.3], to:StringGrid4.#1.4 } 

It consists of some const value bindings (which only temporary exists as bindings while the data is set, and as such are low cost entities that wont affect system performance afterwards), and then it consists of some expression bindings, where data is picked up from various cells of the string grid and the result placed in a designated cell.

Running it, this will show:

I can live, type in any of the value fields resulting in SmartBinding automatically updating the remaining fields based on the expressions.

and if I type invalid data

So we have an advanced spreadsheet, again completely defined at designtime and essentially with only one line of Delphi code, AutoBind.

In fact all these bindings are running live, seamlessly along with several other demo bindings in the next demo app for SmartBinding:

As always.. if you like what you read, share the word, like us, let others know about it!

Happy binding



One thought on “SmartBinding with kbmMW #3”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.