PDA

View Full Version : Type_Exists(sType) ?



ReneMiner
22-08-2014, 14:06
as topic says i try to get a function together that tells me if String sType contains the name of a valid type/udt. Simply trying to dim something like sType always results in an error if sType contains an invalid type. But that's not the intention for this "request".

it's more like


Type t_Type
A As Byte

GetA As Function
SetA As Function
GetB As Function
SetB As Function
'...

End Type

Type t_Type_Private Extends t_Type
B As Byte
End Type

Function t_Type.GetA() As Byte

If Type_Exists( Me.Typename & "_Private" ) Then
Local RealMe Like Me.Typename & "_Private" At VarPtr(Me)
Else
Local RealMe Like Me.Typename At VarPtr(Me)
EndIf

Function = RealMe.A
End Function

'...

Assume Me.Typename would return/contain "t_Type" here...

of course this approach won't work with somehow dimensioned variables since i can not return the base-type only while in reality the variable is the extended type...
but works pretty well when using absolute variables on heaped data and some special way of "dimensioning" ;)