Object help
BlitzMax Forums/BlitzMax Beginners Area/Object help
| ||
Hi, I'm declaring a variable as v:Object, so that I can then do v:Object = New Mytype or v:Object = New AnyType. To be able to use the v, I must use MyType(v).whatever = 100 Later in the program, v will be Nulled and asigned to another type. Is there a way to avoid the cast as it no look pretty! Type MyType Field bigmap[1024*1024] Field first End Type Type MyType2 Field bigmap[1024*1024] Field second End Type GCCollect Print GCMemAlloced() Global a:Object=New MyType GCCollect Print GCMemAlloced() MyType(a).first =200 a=Null GCCollect Print GCMemAlloced() a:Object = New MyType2 MyType2(a).second = 100 GCCollect Print GCMemAlloced() a=Null GCCollect Print GCMemAlloced() |
| ||
no way around it! Although, It can be assigned into a variable of type myType then do the work with the new variable: local b:MyType = myType(a) b.first = 200 |
| ||
Thanks Jesse, that's much better. Jim. |
| ||
I'm not sure I understand what you are trying to do. As Jesse suggets, it's better to store it in a variable. It would be better to have a base "MapType" with the common fields and methods, and then extend it for each type that you need. Then you can have a generic MapType variable that works like the Object variable except you can use the common fields and methods without casting. |