egroups 2 Posted July 9, 2019 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
Микола Петрівський 10 Posted July 9, 2019 (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 July 9, 2019 by Микола Петрівський Share this post Link to post
egroups 2 Posted July 10, 2019 (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 July 10, 2019 by egroups Share this post Link to post
Микола Петрівський 10 Posted July 11, 2019 You will need to manually call TBindings.Notify because your controls are not observable: http://docwiki.embarcadero.com/RADStudio/Rio/en/Tutorial:_Creating_LiveBindings-Enabled_Components As to why even manual call does not work, it is hard to tell without compilable demo. 1 Share this post Link to post
Serge_G 87 Posted September 29, 2019 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
David Schwartz 426 Posted October 3, 2019 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 Posted October 3, 2019 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
Cristian Peța 103 Posted October 4, 2019 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
David Schwartz 426 Posted October 6, 2019 On 10/3/2019 at 7:22 AM, Dany Marmur said: replace ... overhead ... LOL!! Well, that's what the marketing fluff says, right? 🙂 1 1 Share this post Link to post
Lars Fosdal 1792 Posted October 15, 2019 Live bindings were dead to me after a short test. Fragile and slow was not a winning combo. Share this post Link to post
Rollo62 536 Posted October 15, 2019 Why not work and improve ? There were times when also VCL was fragile and slow. Share this post Link to post
Lars Fosdal 1792 Posted October 15, 2019 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