[Runtime] Reflection and global variables (All)
Archives Forums/BlitzMax Bug Reports/[Runtime] Reflection and global variables (All)
| ||
Global reflection variables not creates at runtime.Type T0 Global gid:TTypeId = TTypeId.ForName( "T0" ) Global gid_o:TTypeId = TTypeId.ForObject( New T0 ) Field lid:TTypeId = TTypeId.ForName( "T0" ) EndType Local l0:T0 = New T0 If l0.gid Then Print l0.gid.name() Else Print "ERROR" EndIf If l0.gid_o Then Print l0.gid_o.name() Else Print "ERROR" EndIf Print l0.lid.name() Results: ERROR ERROR T0 Actually I need the global variables. |
| ||
I'm not sure... but here http://www.blitzbasic.com/Community/posts.php?topic=84918 you could find a 'updated' Reflection module. Not sure if the change supports or not your needs about Globals... edit: reading all the thread seems that Globals arent' exposed... |
| ||
Hes complaining about the type not being registerd when he inits his globals... It seems bmx inlines type globals into the module init. And since type registration is in the same spot, it gets called too late. To mitigate this, assign to the globals from the main scope. It might be a bug though ;) |
| ||
Tnx grable, Of cause, I find how to get over of these bug (used the singleton pattern). These code works well with GetID() function: Type T0 Global gid:TTypeId = TTypeId.ForName( "T0" ) Global gid_o:TTypeId = TTypeId.ForObject( New T0 ) Field lid:TTypeId = TTypeId.ForName( "T0" ) Global g_id:TTypeId Function GetID:TTypeId () If Not g_id Then g_id = TTypeId.ForName( "T0" ) Return g_id End Function EndType Local l0:T0 = New T0 If l0.gid Then Print l0.gid.name() Else Print "ERROR" EndIf If l0.gid_o Then Print l0.gid_o.name() Else Print "ERROR" EndIf If l0.GetID() Then Print l0.GetID().name() Else Print "ERROR" EndIf Print l0.lid.name() But, these is overhead (a bit) both code and performance. And these is bug anyway. |
| ||
I agree, that this is probably a bug. On my bcc_ng compiler, I get the following output : T0 T0 T0 because I initialise type globals before executing the local code, which seems the correct thing to do. |