Generalised Scrolling List of Container Controls

Our application has the need for quite a few scrolling lists of container controls. Each list manages a single container type and enables ADD, DELETE and DRAG. Each type of container has its own private logic and behaviour to collect and display data.

In the interests of maintenance and the principle of single responsibility, I was hoping to write a single ListContainer class, with an ADD Button and a Canvas for embedding these different container controls. Drag and drop would be managed by the ListContainer as well as a general property array of live ContainerControls.

When dropped onto a window I would like to “tell” ListContainer1 it is to manage GreenContainer Objects and that ListContainer2 will manage BlueContainer Objects etc.

I am not as yet knowledgeable enough in XOJO to understand how to generalise this scrolling list of container controls such that it can work with any defined type of container objects. I seem unable to break the tight dependency between the “general purpose” ListContainer and each specific type of embedded container.

Am I faced with copying and then hardcoding each ListContainer to work with its specific container control types?

The power of Xojo has continued to amaze me so I “suspect” this is possible. Any seasoned XOJO wisdom in this regard would be most appreciated.

If I am understanding you, it sounds like you want Generics which, unfortunately, Xojo does not have.

You can make a ListContainer work with any type of Container Object by using an interface (or the ContainerControl superclass), but that doesn’t provide a compile-time way for you to restrict the ListContainer to only work on a specific type. To do that, you’ll need separate ListContainers for each type.

If you use an interface, you can check the type at run-time, which perhaps is acceptable.

Paul,

Thanks … This sounds promising. I actually DO wish to check the type at run-time.

Can you expand upon how a Xojo interface might be applied in this context or point me to any examples.

Much appreciated …

Offhand and untested, but maybe something like this could work:

ContainerInterface has common methods defined (or none). Your containers implement this interface:

GreenContainer Implements ContainerInterface BlueContainer Implements ContainerInterface

ContainerList has a way to specify the type it can manage. Perhaps an enumeration and property? It also allows items of type ContainerInterface to be added somehow. If you used a method, it could be something like this:

AddContainer(containerItem As ContainerInterface)

This method could have code to check the type to see if it is one you support:

Select Case AllowedContainerType Case ContainerType.Green If containerItem IsA GreenContainer Then // Add it Else // Error, exception, etc. End If Case ContainerType.Blue If ContainerItem IsA BlueContainer Then // Add it Else // Error, exception, etc. End If End Case

Excellent … I can see how this might do the trick.

Standby for (potential) positive feedback.