TList. To improve array management

Form Employers

In previous two articles we talked about array management: copy by value and copy by pointer methods have been exposed to achieve same results but in different ways.
The former being direct and simply, the latter more powerful but danger (because of risks related to pointers).

If you get familiar with pointers you can understand their usefulness, so that they become sometimes necessary to ease some tasks; but we know their dangerousness!
Nothing stops us from building some construct, or data type thanks to which we can use pointers with a major security degree.

That's probably what people who writes TList types (for every programming language) thinks.
This is because the list is a so powerful and useful and commonly used data structure written for homogeneous elements.
Well... homogeneous! This surely recalls an array. And that's true!

TList is designed on dynamic array (behavior), and the beauty of a TList variable is it contains all functions and procedures needed to manage the array.
Maybe this last sentence is not so clear, but we'll expose everything to make you understand.

Now... what happens by declaring a TList variable?
Basically consider the same as declaring a dynamic array: it's enough for the moment.
Is all ok? Yes?! Indeed... NO!

Which is the items nature?
Here the key: every item is a pointer, precisely a pointer to... we don't know.


The pointer is generic!
This is great: we just made a step up to abstraction. We have a freedom degree more.

And now let's see how to take advantage of this opportunity, because generalization is very beautiful, but remember that we're here to write and test code.