Friday, July 10, 2009

More ooBasic Quirkiness (Custom Type)

Problem with no able to use custom type as global. Basically once it exit a sub/function, the custom type object is whip out. Like this:

Type MyType
Some variables
End Type

Global gMyTypeObject as MyType ' Or as Dim, Public. Or as New MyType. Doesn't matter

Function DoA()
Read gMyTypeObject here but it's always empty...
End Function

Function DoB()
Do something and set gMyTypeObject
End Function

Amazingly this method below works...

Global gMyTypeVarObject as Variant

Function CreateMyTypeObject() as Variant
Dim x as MyType
CreateMyTypeObject = x
End Function

Sub Init() ' Call during initialization
gMyTypeVarObject = CreateMyTypeObject()
End

' Now all functions/subs can see gMyTypeVarObject as an object of MyType.

Brilliant...

No comments: