I urge for some way to determine TypeOf a variable and to conserve it somehow..so it can be used as an Alias for variable-types.
I did different attempts using thinBasic_VariableGetInfoPtr but somehow seems to return randomized different values in MainType and also does not work on Udt-Subsets because can not pass "VarPtr(myVar.X)" and expect valid results from it. TypeOf should work on all primitives - for UDTs it probably would just return %Type_UDT...
Currently I have a function which could use TypeOf-Results - in this case just some Peek-Replacement so I can set arbitrary type to Peek at ptr.
Uses "console"
Begin Const
%Type_Unknown = 0
%Type_Byte
%Type_Integer
%Type_Boolean
%Type_Word
%Type_DWord
%Type_Long
%Type_Quad
%Type_Single
%Type_Double
%Type_Currency
%Type_Ext
%Type_Number = 20
%Type_AsciiZ = 25
%Type_String = 30
%Type_GUID = 40
%Type_Variant = 50
%Type_UDT = 60
%Type_PTR = 70
%Type_Object = 80
%Type_Class = 90
End Const
String sTest = MKL$(12345)
' test Memory_Read:
PrintL Memory_Read StrPtr sTest, %Type_Long
sTest = MKD$(12.345)
PrintL Memory_Read StrPtr sTest, %Type_Double
sTest = "Test"
PrintL Memory_Read StrPtr sTest, %Type_String
PrintL $CRLF + "key to end" + $CRLF
WaitKey
' ----------------------------------------------------
' some Peek-Any-Replacement...
Function Memory_Read( ByVal mPtr As DWord, _
ByVal as_Type As Long _
) As Any
If mPtr Then
Select Case as_Type
Case %Type_Byte
Function = Peek(mPtr)
Case %Type_Integer
Function = Peek(Integer, mPtr)
Case %Type_Boolean
Function = Peek(Boolean, mPtr)
Case %Type_Word
Function = Peek(Word, mPtr)
Case %Type_DWord, %Type_PTR
Function = Peek(DWord, mPtr)
Case %Type_Long
Function = Peek(Long, mPtr)
Case %Type_Quad
Function = Peek(Quad, mPtr)
Case %Type_Single
Function = Peek(Single, mPtr)
Case %Type_Double
Function = Peek(Double, mPtr)
Case %Type_Currency
Function = Peek(Currency, mPtr)
Case %Type_Ext
Function = Peek(Ext, mPtr)
Case %Type_String
Function = Memory_Get(mPtr, Peek(DWord, mPtr-4) )
'Case Else
' not possible - maybe optional passed
' Long Size could extend this -
' but could just use Memory_Get then...
End Select
EndIf
End Function
Now the idea is to have a TypeOf-function that returns some "Replacement" or Value for
BYTE, INTEGER, WORD, DWORD, LONG, QUAD, SINGLE, DOUBLE, EXT, CURRENCY, STRING, ASCIIZ, VARIANT, GUID, (UDT)
that could be used instead of these keywords as well in Peek+Poke and also to dim as ...(except %Type_UDT of course) - even if it would mean to do it alike that:
X = Peek( VarType(myType), myPtr)
Dim Y As VarType(%Type_Long) ' where %Type_Long could be replaced by any variable
Poke( VarType(TypeOf(Z)), Varptr(Z), newValue ) ' String probably not possible here...
|
Bookmarks