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)
Database Details
The application database is defined by three classes contained in the file DBLBO.pas. When instantiated, they form a tree structure not unlike a relational database having two master/detail relationships. Diagrammatically, they appear as follows (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):
Using Delphi LiveBindings With TObject and TObjectList<T>—Part 1 of 4—Overview<==PreviousDelphi Livebinding Objects Data Structure |
The Database Classes
TCorp
This class is instantiated a single time and contains information about the fictitious corporation used in the sample application. In addition, it contains a
TObjectList<TBranch>
property that is used to store all of the instances of Branches owned by the corporation.TBranch
This class is instantiated once for each Branch owned by the corporation and that appears in the
TObjectList<TBranch>
property of the instantiated TCorp
.TBranch
also contains a TObjectList<TEmployee>
property that contains a list of the instances of TEmployee
for all of the employees who are assigned to the corresponding branch.TEmployee
This class is instantiated once for each Employee assigned to the Branch and who appears in the
TObjectList<TEmployee>
property of the corresponding TBranch
.Instantiation Hierarchy
The
Each invocation of the
In this was, as single call to
Create
constructor of TCorp
not only instantiates the TCorp
object; it also creates three arbitrary Branches by invoking the TBranch.Create
constructor for each of the branches.Each invocation of the
TBranch.Create
constructor instantiates the branch and provides arbitrary properties, but also invokes the TEmployee.Create
constructor for each of the employees assigned to the corresponding Branch.In this was, as single call to
TCorp.Create
will result in the instantiation of the entire database.Arbitrary Data
Each of the database object
Create
constructors provides for the specification of arbitrary data when invoking the constructor. In this way, the invoker provides the data needed for the instantiation.Overloaded Creates
The constructors for
TBranch
and TEmployee
have overloaded versions. In one version, the data used to populate the fields of the instance is provided by the invoker. This is the form used when the database objects are first instantiated.
The second form of
Create
does not provide for any values for the properties of the new object. This is the form used when the TBindNavigator
components process the Add (+) button. Type Aliases
The
DBLBO.pas
file also specifies three Type Aliases:CorpObjectBSWrapper
that is aTObjectBindSourceAdapter<TCorp>
.BranchListBSWrapper
that is aTListBindSourceAdapter<TBranch>
.EmployeeListBSWrapper
that is aTListBindSourceAdapter<TEmployee>
.
Using these Type Aliases solves a couple of problems.
- The naming conventions used by LiveBindings are incredibly bad. Class names like
TObjectBindSourceAdapter
,TListBindSourceAdapter
andTAdapterBindSource
make repeated use of the words "Source," "Bind," and "Adapter" with no clear indication of what a given class is supposed to do. Using a TypeAlias to change the name to something meaningful (they really are classes that wrap around Objects and Lists) makes it much easier to develop and understand the code. - The objects referenced by the Type Aliases are, in fact, generic in nature as the Type Alias indicates. This is what prevents their specification as a component in the first place. By using a Type Alias the cumbersome generic notation disappears from view, again facilitating cleaner, more easily understood code.
This completes the examination of the database objects. Next, we'll consider the Model Details.
Next==>Using Delphi LiveBindings With TObject and TObjectList<T>—Part 3 of 4—Model Details
No comments:
Post a Comment