I've been trying to get a method working to copy an instance of a type. This is based on some code I found in an old post.
Method copy:TTemplate()
Local newTemplate:TTemplate = New TTemplate
MemCopy (Byte Ptr(newTemplate), Self, SizeOf(Self))
Return newTemplate
End Method
usage:
myTemplate = template.copy()
Howver, after copying I get array out of bounds errors (for the array within the type) and also bad reference errors. I'm guessing there is something wrong in the way it is allcoating the memory but not sure how to fix it.
I could just copy each individual field & array element but it would be more elegant if I can get it working with memcopy.
|