3
votes

I've had this problem for years but maybe it is now possible to easilty solve it. I need to lay out a panel with several TEdit controls, each should show, and allow editing of, a published property of a class. Traditionally I would use TEdit (or a numeric derivative from the Raize or Developer Express libraries) and 'wire up' the OnKeyPress and OnExit events, convert between the edit text and the property type etc etc. All as per Delphi 1 (whose big birthday is soon!).

These days we have RTTI and Live Bindings, so ideally I'd like a way of telling a TEdit (or another similar control) about a single published property and the necessary 2-way link would then be established without all the wiring up and conversions. An object inspector does this job of course, but I'd like a more formal custom layout using labelled edit controls. It would be fine to simply cope with integer, float and string, and something like a TDBEdit where the field name was my property name would be great.

I've taken a look at the 'Bind Visually' designer (I have XE3) but I'm on to uncertain ground. Can anyone suggest a means of doing this? Thanks.

1
I found the LiveBindings tutorial pretty simple to follow, and pretty complete about binding controls to object properties. It's in the XE3 help file, too (Topics->RAD Studio->RAD Studio Topics->Tutorials). There's a specific example of using a TEdit in Using TPrototoypeBindSource and the LiveBinginds Designer tutorial, along with some other controls.Ken White
Not all controls are fully supported by LiveBindings and you need to wire up some events. As an alternative you should have a look at MVVM PatternSir Rufo
@Brian: Found an example of binding to a plain old class here that might help. It's located in your Users\Public\Documents\RAD Studio\10.0\Samples\LiveBindings\BOCollectons folder.Ken White
Not strictly 'Delphi' but Lazarus has exactly what I was looking for using 'RTTI Controls' wiki.lazarus.freepascal.org/RTTI_controlsBrian Frost

1 Answers

1
votes

The comments above by Ken White and Sir Rufo are good pointers to the use of Live Bindings for wiring up components between each other, but I need to wire up controls to my own object and which is created at runtime. Further digging led me to this excellent article which pretty much does what I want. Jarrod's TBoundObject is intended to be the ancestor for your own objects, but by including an FObject field passed in the constructor and replacing his use of 'Self' by FObject, you can instantiate a standalone 'TObjectBinder' that easily connects various standard controls to published properties.