![]() Procedure TFormBindings.btnUpdateObjClick(Sender: TObject) With this code, when the data changes, the UI refreshes automatically to reflect it: Procedure TMyObject.SetName(const Value: string) In fact, all you need to do to instrument the object is to notify the system that the value has changed: But the object should have no knowledge of the user interface controls or the UI bindings. Again, refreshing the expression updates the output. Its Name property is associate with the edName component Text. In this code MyObj is an object of the TMyObject class. Here is how you can bind an object to the UI:Ä«indingExpressionObj := TBindings.CreateManagedBinding( The TMyObject class has a Name and a Value property. This is better explained in the second part of the example, which has an edit box bound to an object in memory. We'll get to it, but let me show the simple application UI first: This change of perspective (a value has changed rather than an expression needs to be recalculated) is of a fundamental importance, as it fully abstracts the data model from the UI it is associated with. Procedure TFormBindings.SpinEdit1Change(Sender: TObject) The system will automatically determine if there is one or more expressions involving the property and refresh it: You can make the same call to refresh the value, but you can also abstract the concept by indicating to the bindings architecture that the value property of the spin edit has changes. With this configuration code, if you call BindingExpression1.Evaluate the value of the SpinEdit will be copied to the ProgressBar. You can also specify an output converter, which I've omitted here:Ä«indingExpression1 := TBindings.CreateManagedBinding( As you can see in the code below, each object is associate to the expression providing a name, like spin1 for the SpinEdit1 component, and the expression can refer to the object and its properties, as in spin1.Value. A managed binding allows you to provide an input expression (with one or more input objects) and an output expression (again with one or more objects). In practical terms, suppose you have a form with a SpinEdit and a ProgressBar. In this case we don't simply evaluate an expression, but want to associate two separate expressions in a "binding". I want to explain how components and their properties can be part of these expressions. Last week I introduced Delphi RTL expression engine in the blog post at. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |