How to resize dynamic array of user defined type?
BlitzMax Forums/BlitzMax Beginners Area/How to resize dynamic array of user defined type?
| ||
Hi All, I have a dynamic array of a user defined type (TSlice). I'd like to add an element to it. The code below reports that the element has been added, but when trying to access the element it throws an exception "Unhandled Exception: Attempt to access field or method of Null Object". Strict Graphics 1024,768 Type TSlice Field x:Int Field y:Int Field img:TImage End Type Local a:TSlice[] DebugStop Print Len(a) 'returns 0 a = a[ .. Len(a)+1] Print Len(a) 'returns 1 as expected a[0].x = a[0].x ' causes error - Unhandled Exception: Attempt to access field or method of Null Object Maybe the resizing of the array is not creating a new TSlice object and I need to do that manually. I'm not sure, any ideas? Thanks, Jon |
| ||
Well, a[0] is NULL, so the error. You still need to 'define' each item of the user-type array a[0]=new Tslice |
| ||
Thanks! :o) |