In the first and second episodes of this trilogy, we demonstrated the basics of ORDA using list boxes, entities, and entity selections. We also showed the way to use similar list boxes with distinct data sources and how to use Meta info expression to improve the list boxes’ graphics.
Today we’re going to have even more fun, with less code!
Less code, more fun!
Based on the recursive structure we discussed before, our goal today is to display a family tree (as shown below).
For each couple, we want to display their parents, grandparents, and their children (if they have any).
The list on the left will display all couples for whom we will find four parents and eight grandparents. This going to be the main challenge.
To display couples on the left, we can limit the search to men with partners:
Gender=false // boolean field
and partner # null
But we’ll also need to be sure they both have parents:
and Father # null
and Mother # null
And then we’ll need to check for grandparents, etc., etc.
Magic and logic
If 4D (and ORDA) can be queried to find four grandparents to the partner of X, that also means that X has a partner and that his partner has a father and a mother as well. So in the end, it’s quite simple! We just have to check that each member of the couple as four grandparents !
Gender=false // search for men only (his partner's name will be displayed next to his)
and Father.Father # null // check for the man's grandparents
and Father.Mother # null
and Mother.Father # null
and Mother.Mother # null
and Partner.Father.Father # null // check for his partner's grandparents
and Partner.Father.Mother # null
and Partner.Mother.Father # null
and Partner.Mother.Mother # null
Done! This is the entity selection that will be used on the left side of the form.
No more code?
Almost. Except for the kids that we’ll manage later, no more code is needed!
Just remember, in the list box properties there is a property called current item. Just name it … then use it! In this case, the current item is “man”. So as soon as you click on any row of the listbox, the man entity is updated and you can use and display his attributes without any coding.
Not only his attributes, but also all the attributes of related entities, and the attributes of related entities of related entities … so in your form you can display expressions like:
Or more complex expressions like:
As we said: No code! Only expressions! Just pay attention when using copy-paste … it could prove to be your greatest enemy sometimes 🙂
What about kids?
They’re quite simple, too. During the On selection change event, simply create an entity selection of children (see episode 2), then loop through this entity selection to build the names and pictures !
: (Form event=On Selection Change)
childrenPortraits:=childrenPortraits*0 // erase picture
childrenNames:="" // erase names
$_children:=GetChildren (men) // get the entity selection of children
For each ($child;$_children)
COMBINE PICTURES(childrenPortraits;childrenPortraits;Horizontal concatenation;$child.Portrait_0)
childrenNames:=childrenNames+$child.Firstname+" ("+String($child.Birthday)+") "
End for each
Conclusion (or beginning!)
With these three episodes, we’ve given you a tiny preview of the power of ORDA. Some of the results we’ve shown were nearly impossible to get using 4D in a regular and simple way. Huge numbers of lines of code, arrays, memory, and calculations would have been required to reach the same results. We’re not saying that every 4D database should be rewritten with ORDA (“If it’s not broke, don’t fix it” is one of my favorite quotes), but it’s quite obvious that for your future databases or current ones (if they need improvement), ORDA will be a great help and time saver!