SetLength
is used to resize dynamic arrays and long strings. To resize a variant array you use VarArrayRedim
.
Another option is to build your list of elements in a temporary container of type TList<T>
. When you are finished, you can use the Count
property of that container to size the variant array once and for all. And then you'd copy across the actual values.
I think it makes little difference which approach you use.