This is the line I suspect is causing the problem:
CopyMemory tColElem, ByVal tColElem.PtrNext, LenB(tColElem)
If tColElem contains data referenced by pointer, then that line basically creates an unreferenced copy of the data. Let's say it's string data in the tColElem.Data item. When your function exits, whatever is in that element is destroyed and when later referenced as part of the collection or collection is destroyed - crash.
You'll want to zero out the tColElem when the loop ends. Can do this with an array of LenB(tColElem) or FillMemory API.
Code:Dim tNullData() as Byte ReDim tNullData(1 to Lenb(tColElem)) For ... Next ... CopyMemory tColElem, tNullData(1), UBound(tNullData) ...




Reply With Quote