Blog

All Blog Posts  |  Next Post  |  Previous Post

Multi component, multi data source binding in FNC

Friday, March 26, 2021

Intro

We have been working on multi component, multi data source binding for quite some time now, providing a foundation for future improvements and new features and today we can proudly announce that TMS FNC Core 2.5 makes the first version available via the TTMSFNCDataBinder component. The TTMSFNCDataBinder component is a non-visual component that acts as a bridge between components and datasources and uses RTTI to detect bindable properties.


Read-only

Important to know is that this initial release of the TTMSNCDataBinder component supports read-only data binding. It listens to dataset changes, and automatically updates values in the component. In future updates, writing data to the dataset is planned as well as updating the active record based on the selection.


Supported modes

The TTMSFNCDataBinder component supports 4 modes:

  • single value
  • list
  • column/list
  • grid (via interface)


TMS Software Delphi  Components

To point out how a binding is done, below is a sample of binding a single value and a list component. (Based on TTMSFNCHTMLText and TTMSFNCListBox)

single value

TMS Software Delphi  Components

procedure TFormDataBinding.UpdateLinks;
var
  it: TTMSFNCDataBinderItem;
begin
  TMSFNCDataBinder1.BeginUpdate;
  it := TMSFNCDataBinder1.Items.Add;
  it.&Object := TMSFNCHTMLText1;
  it.BindType := dbbtSingleValue;
  it.DataSource := DataSource1;
  it.FieldName := 'Common_Name';
  it.PropertyName := 'Text';
  TMSFNCDataBinder1.EndUpdate;
  TMSFNCDataBinder1.Active := True;
end;
The below code actually sets up the same binding as the code above with a convenience method ConnectSingle.

procedure TFormDataBinding.UpdateLinks;
begin
  TMSFNCDataBinder1.ConnectSingle(TMSFNCHTMLText1, DataSource1, 'Text', 'Common_Name');
  TMSFNCDataBinder1.Active := True;
end;

list
procedure TFormDataBinding.UpdateLinks;
var
  it: TTMSFNCDataBinderItem;
begin
  TMSFNCDataBinder1.BeginUpdate;
  it := TMSFNCDataBinder1.Items.Add;
  it.&Object := ListBox1;
  it.BindType := dbbtList;
  it.DataSource := DataSource1;
  it.FieldName := 'Common_Name';
  it.PropertyName := 'Items';
  TMSFNCDataBinder1.EndUpdate;
  TMSFNCDataBinder1.Active := True;
end;


Again as with the single value binding, the below code uses a convenience method to add an item and set all the properties in one go.


procedure TFormDataBinding.UpdateLinks;
begin
  TMSFNCDataBinder1.ConnectList(ListBox1, DataSource1, 'Items', 'Common_Name');
  TMSFNCDataBinder1.Active := True;
end;

TMS Software Delphi  Components


HTML template

For the single value and list bindings, there is support to add a HTML template instead of binding to a specific field name. The HTML template supports multiple fields as long as they follow a specific kind of format. The HTML itself is based on the mini HTML reference (https://www.tmssoftware.com/site/minihtml.asp)

The format for adding fields is: <#FIELDNAME>.

So when applying this to the single value binding for example we can add an item using the

TMSFNCDataBinder1.ConnectSingleHTMLTemplate(TMSFNCHTMLText1, DataSource1, 'Text', '<b>Name: <#COMMON_NAME></b><br/><#NOTES>');

or

procedure TFormDataBinding.UpdateLinks;
var
  it: TTMSFNCDataBinderItem;
begin
  TMSFNCDataBinder1.BeginUpdate;
  it := TMSFNCDataBinder1.Items.Add;
  it.&Object := TMSFNCHTMLText1;
  it.BindType := dbbtSingleValue;
  it.DataSource := DataSource1;
  it.PropertyName := 'Text';
  it.HTMLTemplate := '<b>Name: <#COMMON_NAME></b><br/><#NOTES>';
  TMSFNCDataBinder1.EndUpdate;
  TMSFNCDataBinder1.Active := True;
end;


TMS Software Delphi  Components


Editor

The databinder component installs an editor that is available at designtime and at runtime. The editor allows to visually edit the bindings that you have set up. You can also create, update and delete new or existing bindings. To start it at runtime, call

TMSFNCDataBinder1.ShowEditor;

At designtime, you can right-click the TTMSFNCDataBinder component and select “Edit…” to start the editor.

TMS Software Delphi  Components


Want to know more?

Active registered users of FNC (TMS FNC Core) can download the update and get started right away! A demo ("Databinding"), is included in the distribution and there is separate documentation that gives more details on what the TTMSFNCDataBinder component can do and can mean for your application.





Pieter Scheldeman




This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post