SetLength and multidimensional dynamic array

Viewed 111

I have to work with arrays of arrays of Tpoint. I don't know any initial dimension because the user will be able to create n groups of Point each of which with variable dimension.

It involves working with figures, each initial figure has four vertices and it is possible to model it, add and remove vertices.

I define the type

type
Tnode = array of array of TPoint;
...
Fnode: Tnode;

When I create a new figure I initialize the array

SetLength(Fnode, index, 5);

Then I modify the figure by adding and removing vertices, setting the new dimension each time

SetLength(fnode[index-1], nVertices);

Everything works best but when I create a new starting figure with SetLength (Fnode, newIndex, 5) the previous array is also initialized to 5 again and any vertices added are obviously deleted.

At the moment I solved by copying the arrays before creating a new figure and restoring them after calling SetLength but it seems like bad practice.

Do you have any suggestions?

0 Answers
Related