Jump to content

Recommended Posts

Hello,

I tryed generate LiveBindings by Code.

I am used from example this code

procedure Bind(const Source: TObject; const SourcePropertyName: string; const Target: TObject; const TargetPropertyName: string);
var
  lSrcProperty,lDstProperty:string;
  lAssocInput,lAssocOutput:IScope;
  lManaged:TBindingExpression;
begin
  lAssocInput:=TBindings.CreateAssociationScope([Associate(Source,'Src')]);
  lAssocOutput:=TBindings.CreateAssociationScope([Associate(Target, 'Dst')]);
  lSrcProperty:='Src.'+ SourcePropertyName;
  lDstProperty:='Dst.'+ TargetPropertyName;
  lManaged:=TBindings.CreateManagedBinding(
    [lAssocInput],lSrcProperty,
    [lAssocOutput],lDstProperty,
    nil, nil,[coNotifyOutput]);
  BindingExpressions.Add(lManaged);
end;

This is OK if I used for example:

Bind(srcViewModel,'String',dstEdit,'Text')
Bind(srcViewModel,'Number',dstEdit,'Text')
Bind(srcViewModel,'Boolean',dstCheckBox,'Checked')

But I have srcViewModel.Container.DataSource and on form DBGrid (I NEED DBGrid).

When I Use

Bind(srcViewModel,'Container.DataSource',dstDBGrid,'DataSource')

is OK,but when I use TBindings.Notify application says DBGrid don't have property DataSource.

 

Why?

What problem when I binding DataSource to DataSource?

Share this post


Link to post

Maybe, you should try

Bind(srcViewModel.Container,'DataSource',dstDBGrid,'DataSource')

?

But in general, this looks suspicious to me. Usually LiveBindings are used to replace data-aware controls, and you are trying to mix them. What do you want to achieve?

Edited by Микола Петрівський

Share this post


Link to post

I tryed Bind(srcViewModel.Container,'DataSource',dstDBGrid,'DataSource'),no error,but DataSource not binded,DBGrid.DataSource not Assigned.

In srcViewModel I call

TBindings.Notify(self,'Container'); //nothing
TBindings.Notify(self,'Container.DataSource'); //nothing

Edited by egroups

Share this post


Link to post

Hi, sorry for delay but if it is still in actuality  here is how i make this

with  TBindGridLink.Create(Self) do
  begin
      ControlComponent := Grid1;
      SourceComponent := AdapterBindSource1;
      // Filling Grid
      ColumnExpressions.AddExpression; // adding a right filler
      with ColumnExpressions.AddExpression do // ColumnName = 'Code', ColumnIndex = 1
        begin
          SourceMemberName := 'Code';
          with FormatCellExpressions.AddExpression do
            begin
              ControlExpression := 'Data';
              SourceExpression := 'Value';
            end;
        end;
	  // an so on for columns 
	  
	  // MANDATORY TO NAVIGATE 
      // Position (synchronisation entre la liste et la grille)
      with PosControlExpressions.AddExpression do
        begin
          ControlExpression := 'Selected';
          SourceExpression := 'Math_Max(0,ItemIndex)';
        end;
      with PosSourceExpressions.AddExpression do
        begin
          ControlExpression := 'Math_Max(0,Selected)';
          SourceExpression := 'ItemIndex';
        end;
		
      // Working on columns size
      with FormatControlExpressions.AddExpression do
        begin
          ControlExpression := 'Columns[0].width';
          SourceExpression := '20';
        end;
      with FormatControlExpressions.AddExpression do
        begin
          ControlExpression := 'Columns[1].width';
          SourceExpression := '140';
        end;
      // and so on ...
  end;

 

Share this post


Link to post

As was asked earlier, why are you trying to use LiveBindings with a data-aware control in the first place?

 

LiveBindings were designed to replace the need (and overhead) of data-aware controls. Even if you get this example working, I think it might end up causing strange problems at run-time because the data-aware control events could trigger LiveBinding events and either go in circles or undo each other.

Share this post


Link to post
Guest
7 hours ago, David Schwartz said:

 

LiveBindings were designed to replace the need (and overhead) of data-aware controls.

replace ... overhead ... LOL!!

Share this post


Link to post

Actually LiveBindings replaced the data-aware controls overhead. With a worse one.

But... that this was by design... this is something new to me.

Share this post


Link to post
On 10/3/2019 at 7:22 AM, Dany Marmur said:

replace ... overhead ... LOL!!

Well, that's what the marketing fluff says, right? 🙂

  • Like 1
  • Haha 1

Share this post


Link to post

Live bindings were dead to me after a short test.

Fragile and slow was not a winning combo.

  • Like 1

Share this post


Link to post

Why not work and improve ?  There were times when also VCL was fragile and slow.

Share this post


Link to post
5 minutes ago, Rollo62 said:

Why not work and improve ?  There were times when also VCL was fragile and slow.

We already had something else doing the job for us, so we had no need to transition to it.

 

The fragile bit can be only be eliminated when we get a NameOf compiler magic function. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×