GetMem(ApArray, ElementCount * SizeOf(tStructures)); // (0)
The error probably depends on "string" being ansi- or short-string.
This looks like a normal Lazarus project, and likely contains a {$H+} => use ansistring.
**s://www.freepascal.org/docs-html/rtl/system/getmem.html
The newly allocated memory is not initialized in any way
And this then can be affected by
- the OS
- the mem manager your app uses (default, cmem, heaptrc
In any case the memory contains just random bytes.
An ansistring is a pointer to internally managed data. That data must be initialized. If the ansistring-pointer is random data, then it expects this to point to valid-(string-)initialized memory...
Well and it does not, it point somewhere random.
And Btw, if you get zero filled mem, and you put ansistring in there like this, and you FreeMem the array => memory leak.