Source Code
The source code in the form of a Delphi Project Group is available at:
The project was developed using Delphi RAD Studio Tokyo (10.2.2)
VIEW Details
This is the simplest part of the demo. This is in keeping with our objectives of making the VIEW as trivial a possible to facilitate testing. It also results in a very clean separation of concerns, effectively removing all data manipulations from the VIEW. The use of LiveBindings further isolates the VIEW from other parts of the application.
Create and Destroy
The
FormCreate
and FormDestroy
events are used to create and free the MODEL. The pointer to the MODEL is saved as a property of the form.Binding the UI Objects to the MODEL
LiveBindings is used to connect the data elements of the MODEL to the UI objects seen by the User. The Visual LiveBindings used to accomplish this appear in the following illustration. There are no other bindings or code fragments used to display the data. The entire VIEW is handled by LiveBindings without needing any other code. (A full-sized PDF of this diagram is also to be found in the Docs folder of the Github project or can be downloaded here.)
Several things should be observed in order to achieve this result:
Delphi LiveBindings Demo Visual LiveBindings |
- Work from the VIEW, not the MODEL. In other words, be sure you have
VULBO.pas
, the Form, selected in the IDE. Then invoke "Bind Visually." - Be sure you have specified
MDULBO
(your Model Unit Name) in the VIEW (VULBO
)Uses
clause. This will enable the Visual Designer to access the necessaryTBindSource
instances. - The Items in the Branch
TListView
have been customized by setting theItemAppearance
property toDynamicAppearance
and adding theItem.Text1
,Item.Text2
andItem.Text3
fields. This discussion does not address how that is accomplished and I assume you already know how to do that or you can find a way to learn about it.
- For bindings that bind to
ObjectList<T>
properties, be sure to connect theTListView
Synch
property with the Asterisk (*) item of theTListBindSourceAdapter
. In the diagram above, these are namedMDLBO.absEmployees
andMDLBO.absBranches
respectively. This will permit scrolling operations on the lists to take place correctly. The remaining item,MDLBO.absCorp
is not a list; it is a single object. So it cannot be synched.
Conclusion
The discussions and techniques presented here should enable a developer to utilize LiveBindings effectively with both Objects and ObjectLists for real-world development. Of course, there are endless variations to the patterns shown, but regardless of the details of any particular implementation, the fundamental principles used to manage LiveBindings with Objects and ObjectLists remain; developers who understand the fundamentals will be able to expand and adapt the fundamentals to the particular needs of their application.
If you made it this far, thanks for reading and (I hope) understanding! Part 3 is especially daunting because of the number of things that must be managed and coordinated, all of which is compounded by the severely inadequate and confusing naming conventions (if they can be called conventions at all) of LiveBindings.
When all is said and done, it is pretty cool. Enjoy!
Using Delphi LiveBindings With TObject and TObjectList<T>—Part 3 of 4—Model Details<==Previous
Hi Milan,
ReplyDeletegreat, great Article! Thank you very much to shared it's with us!
Claudio
Thank you very much for this sample project and accompanying posts. Very useful and well done. Very much appreciated.
ReplyDelete