first usage-test looks good
Uses "console"
Uses "TBGL" ' for the color-type
Function fTestRed(ByRef lColor As Byte)
PrintL lColor
End Function
Function fTestGreen(ByRef lColor As Byte)
PrintL lColor
End Function
Function fTestBlue(ByRef lColor As Byte)
PrintL lColor
End Function
Dim myColor As TBGL_TRGB
myColor.R = 1
myColor.G = 2
myColor.B = 3
fTestRed( myColor.R )
fTestGreen( myColor.G )
fTestBlue( myColor.B )
PrintL $CRLF & "----------------------------------> any key to end"
WaitKey
Edit:
could not resist to try out strings... at least we have some testscript already:
Uses "console"
Function StrAt(ByRef s As String) As String
Local p As DWord At VarPtr(s)
If p Then Function = Memory_Get(p, Peek(DWord, p - 4))
End Function
Type t_testtype
s As String
End Type
Dim sTest As String = "we test simple string"
PrintL StrAt( sTest )
$aConst = "constants seem to work too..."
PrintL StrAt( $aConst )
Dim foo As t_testtype
foo.s = "we test succesful udt"
PrintL StrAt( foo.s )
PrintL $CRLF & "----------------------------------> any key to end"
WaitKey
++ Edit one more since now it's possible - but kind'a off-topic:
To explain, thinBasic allows very much heavy usage of string-content to control program flow, For example "Call_IfExists", "Dialog New Name", "Dim ... Like" etc.
All the Strings like dialogs names, function-names-components, "_mouse", "_click", "_wheel" whatever- have to be stored once only but not to each and every object.
Currently I use for this Heap-memory, store each string once, assign only the pointer to the objects and use Heap_Get(object.hPtr) to read it out.
For a more common usage and people who like to prefer strings to store string-data it would be adequate to have some similar easy way of assigning the same string-text-content to multiple objects without having to store a string twice- that brings us to $StringConstants .
Now currently:
' there would be a long list of styles, events, f.e.
$CS_Window = "Window"
' some control-style be "Window"
' the pointer to that const is a unique number that gets assigned to some .Style-property (DWord)
' of an imaginary t_Control-udt now
Dim Ctrl(123) As t_Control
Ctrl(1).Style = StrPtr($CS_Window)
' and now we can pass this t_Control.Style-Dword BYREF to read its String-content out -
' so it does not create additional variables here
' as well as to identify the style without comparing strings
' because it's globally the same number to all of these "Window"s
' btw. assures all Ctrl()-members have the same fixed size for this property
' somehow then it comes to something like that:
If lEvent Then
Call_IfExists "" & StrAtPtr$( Ctrl(current).Style ) & StrAtPtr$( lEvent )
EndIf
and that's why i would like to suggest it (again?) since it works on udts too now, below contained simple function StrAtPtr$ which returns the String from a pointer
Function StrAtPtr$(ByRef p As DWord) As String
' returns string at p - assumed p is a valid StrPtr
If p Then Function = Memory_Get(p, Peek(DWord, p - 4))
End Function
' ##################################
' other usage: 2 ways...
Uses "console", "dictionary"
DWord mydict = Dictionary_Create(100)
' DWord myPtr = <uncomment and pull code below up>
Dictionary_Add(myDict, "test", "I am some important string")
Dim myPtr As DWord At Dictionary_Exists(myDict, "test") ' < comment this line then >
PrintL "Dictionary content at myPtr :"
PrintL StrAtPtr$(myPtr)
WaitKey
Bookmarks