it's the impossibility to pass udt-elements ByRef, thinBasic will not accept these,
see here:
Uses "console"
Function f_byref(ByRef lLong As Long) As Long
Function = lLong
End Function
Dim bac As Long = 12345 ' normal variable no problemo
PrintL Str$( f_ByRef( bac ) )
WaitKey
Type t_Test
abc As Long
End Type
Dim foo As t_Test
foo.abc = 123 ' but udt-element gets refused as parameter
PrintL Str$( f_ByRef( foo.abc ) )
WaitKey
ByRef is of no use for udt-elements, it's not possible to pass them as function-parameters by reference directly
one always has to do something like this to pass them byRef:
Uses "console"
' either pass a pointer and create a layover in the function:
Function f_byPtr( ByVal pLong As DWord ) As Long
Local lLong As Long At pLong
Function = lLong
End Function
Type t_Test
abc As Long
End Type
Dim foo As t_Test
foo.abc = 54321
PrintL Str$( f_ByPtr( VarPtr foo.abc ) )
WaitKey
' or create layover in advance:
Function f_byref(ByRef lLong As Long) As Long
Function = lLong
End Function
Dim toPass as Long At VarPtr(foo.abc)
PrintL Str$( f_ByRef( toPass ) )
WaitKey
Best would be if udt-elements would be accepted using normal syntax (Byref).
If that's not possible - however..., why..., i don't care the reason... it could be substituted using ByPtr. Means
Function myFunc(ByPtr lVar As someType )
the function automatc creates a local layover lVar As someType At passed pointer.
ByPtr of course awaits a pointer passed ByVal then. It would additionally enable automatic layover at some heap or StrPtr.
But i would be satisfied already if i could just pass the UDT-element ByRef.
Bookmarks