Your question has already put you ahead of me with programming skills, so Iβll just add how I could approach this:
If I tried to write something like this, I would probably start with a TList for each field in your TBusinessObject. This list will be used to indicate what needs to be updated when you need to push changes.
So, when TEdit is created, it will add itself to the list that was associated with the data part in your TBusinessObject. When TBusinessObject updated this piece of data, it will then go through the list of connected objects. He will see TEdit and, knowing that it is TEdit, will run the code for updating .Text. If I attach TCaption, then the code will update .Caption.
TEdit, as you indicated, will have to inform TBusinessObject when it is updated. I think this is a difficult place - you can create a new TEdit and add a TList to support who it should let you know when it changes. If you used .Tag to indicate the field number in TBusinessObject, then OnChange (or any other event) might trigger something like TBusinessObject.FieldUpdate [TEdit.Tag, NewValue], which then triggers your business logic. This, in turn, can cause TBusinessObject to update other fields, which may have their own TLists for updated fields.
Preventing circular updates will require that you have a way to update the control without triggering events. For the one program I wrote, I had two methods for updating the control: SetValue and ChangeValue. SetValue disabled any events (OnChange, OnValidate), updated the control value, and then re-enabled the events. ChangeValue simply changed the value and resolved any of the control events as required.
There are probably easier ways to do this, but hopefully this gives you food for thought.
user496736
source share