The ChildrenListBox Control features an "
ItemContainer" property. If you leave it blank, the Control assume the items to be listed are children of the current object (hence the name
ChildrenListBox). In version 2.2, ItemContainer allowed you to specify other places to find the items like in a child-container, of the current object, or any other container in Premise Space. However, without going into the ugly little details, I wasn't happy with the way I implemented it and, although it worked, it seemed like a kludge and, as we all know, kludges work only under very specific conditions.
It didn't take long for me to bump into the limitations imposed by the kludge. Here's a simple failure scenario:
- Your module creates a new Home object called Gizmo.
- Upon its creation, Gizmo creates a folder called Gizmos, under Premise's existing Media folder (sys.Media.Gizmos).
- You have a ChildrenListBox Control whose ItemContainer points to: sys.Media.Gizmos.
- All seems well and works fine.
It all falls apart after you export the Module (and its Plugins) and then
try to import it on another PC. The problem is that
sys.Media.Gizmos does not exist on the new PC. It won't exist until your module is imported and the Gizmo Home object is created. Unfortunately, that's
far too late in the game for the ChildrenListBox! The moment the module is imported, the ChildrenListBox's ItemContainer property demands to find sys.Media.Gizmos ... and fails. Premise displays the error as an Event and you're left scratching your head wondering how to fix the problem. V2.3 fixes it and then some.
ABControls V2.3 changes the ChildrenListBox's ItemContainer property in a way that solves the problem and makes it more flexible as well. In V2.3,
ItemContainer doesn't point directly to the the desired container but to an
ObjectRef property you create in your module. In turn,
the ObjectRef property points directly to the desired container.
Code:
ChildrenListBox's ItemContainer ---> YourObjectRef ----> DesiredContainer
Since ItemContainer points to an ObjectRef in your module, it has nothing to carp about at the moment the module is imported; the ObjectRef exists at all times. I can hear you say, yeah but ItemContainer is not pointing to the container I want; it's pointing to an ObjectRef that points nowhere. When does the ObjectRef get pointed to the right place?
The answer is so simple and elegant it'll make you smile. Shortly after your module has created the desired container, set the ObjectRef property to point to the newly created contrainer! As a result, the ChildrenListBox's ItemContainer will be pointing to the newly created container. Neat.
An added benefit of this technique ('multiple indirection'), is that you can change what the ObjectRef points to
'on-the-fly'. That means the items listed by the ChildrenListBox can be modified as needed. Here's an example:
You have two ChildrenListBox Controls, one lists people and another lists the person's phone numbers. The data is stored in Premise like so:
Code:
Media
Contacts
John
Cell
Home
Mary
Office
Cell
The children of Contacts are John and Mary.
The children of John are Cell and Home.
The children of Mary are Office and Cell.
The first ListBox contains John and Mary. The second ListBox contains the phone numbers of whoever you selected in the first ListBox. If you pick 'John', his phone numbers (Cell, Home) appear in the Phone ListBox. If you pick 'Mary', her phone numbers (Office, Cell) appear in the Phone ListBox.
For all of that to work, the Phone ListBox's ItemContainer
has to change 'on-the-fly' based on the person selected in the People ListBox. Version 2.3 ChildrenListBox can handle that situation easily.