In some inherited legacy code, I’ve traced a problem with random garbage appearing in output to a non-initialized data structure. It’s defined as:
MyArray: array of array of ShortString;
As we read values from this structure, we’re sometimes getting junk that is clearly coming from a Bad Place, and which changes every time we run it.
I thought that this would be the correct way to initialize this array:
FillChar (MyArray, SizeOf (MyArray), 0)
However, as I started reading various sites, I began to doubt myself. Is that the best/correct way to initialize this array? Is 0 the correct FillValue, or should it maybe be #32?
Afaik shortstrings are not auto initialized. So, setlength to the right sizes, e.g.
then set the length of all strings to 0: