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
Posted (edited)

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
Posted (edited)

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

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

×