ErosOlmi
11-05-2009, 08:10
Next thinBasic preview will have STATIC UDT Elements.
_________________________________________________
Static elements are elements in common to all UDT variables derived from the same UDT TYPE.
They are not part of the UDT structure itself but are available to all UDT of the same type.
Static variables retain their values as long as the program is running.
See following example:
uses "console"
type tUDT
'---Static elements will retains their values for the run of the application
'---Static elements are in common to all variables of type TUDT
static sLong as long
static sLong2 as long
static sStr as string
static MyStaticArray(10) as long
static MyStaticStringArray(100) as string
lLong as long
end type
dim MyUDT_1 as tUDT
dim MyUDT_2 as tUDT
MyUDT_1.lLong = 123
MyUdt_1.sLong = 999
MyUdt_1.sStr = "Whatever string can be applied to a string static element"
printl "Size of MyUDT is: " & sizeof(MyUDT_1.lLong)
printl string$(70, "-")
printl " MyUDT_1.lLong:", MyUDT_1.lLong
printl " MyUDT_1.sLong:", MyUDT_1.sLong
printl " MyUDT_2.sLong:", MyUDT_2.sLong
printl " MyUDT_2.sStr :", MyUDT_1.sStr
printl string$(70, "-")
MyUdt_1.sLong = MyUdt_1.sLong + 999
printl " MyUDT_2.sLong:", MyUDT_2.sLong
printl string$(70, "-")
MyUdt_1.MyStaticArray(10) = 10
printl " MyUdt_1.MyStaticArray(10):", MyUdt_1.MyStaticArray(10)
printl string$(70, "-")
MyUdt_1.MyStaticStringArray(98) = "Again whatever string alloved in a static string element."
MyUdt_2.MyStaticStringArray(99) = "Static elements are in common to all UDT of the same type"
MyUdt_2.MyStaticStringArray(100) = "so changing in one variable will also effect all the others."
printl " MyUdt_2.MyStaticStringArray( 98):", MyUdt_2.MyStaticStringArray(98)
printl " MyUdt_1.MyStaticStringArray( 99):", MyUdt_1.MyStaticStringArray(99)
printl " MyUdt_1.MyStaticStringArray(100):", MyUdt_1.MyStaticStringArray(100)
printl string$(70, "-")
printl
waitkey
_________________________________________________
Static elements are elements in common to all UDT variables derived from the same UDT TYPE.
They are not part of the UDT structure itself but are available to all UDT of the same type.
Static variables retain their values as long as the program is running.
See following example:
uses "console"
type tUDT
'---Static elements will retains their values for the run of the application
'---Static elements are in common to all variables of type TUDT
static sLong as long
static sLong2 as long
static sStr as string
static MyStaticArray(10) as long
static MyStaticStringArray(100) as string
lLong as long
end type
dim MyUDT_1 as tUDT
dim MyUDT_2 as tUDT
MyUDT_1.lLong = 123
MyUdt_1.sLong = 999
MyUdt_1.sStr = "Whatever string can be applied to a string static element"
printl "Size of MyUDT is: " & sizeof(MyUDT_1.lLong)
printl string$(70, "-")
printl " MyUDT_1.lLong:", MyUDT_1.lLong
printl " MyUDT_1.sLong:", MyUDT_1.sLong
printl " MyUDT_2.sLong:", MyUDT_2.sLong
printl " MyUDT_2.sStr :", MyUDT_1.sStr
printl string$(70, "-")
MyUdt_1.sLong = MyUdt_1.sLong + 999
printl " MyUDT_2.sLong:", MyUDT_2.sLong
printl string$(70, "-")
MyUdt_1.MyStaticArray(10) = 10
printl " MyUdt_1.MyStaticArray(10):", MyUdt_1.MyStaticArray(10)
printl string$(70, "-")
MyUdt_1.MyStaticStringArray(98) = "Again whatever string alloved in a static string element."
MyUdt_2.MyStaticStringArray(99) = "Static elements are in common to all UDT of the same type"
MyUdt_2.MyStaticStringArray(100) = "so changing in one variable will also effect all the others."
printl " MyUdt_2.MyStaticStringArray( 98):", MyUdt_2.MyStaticStringArray(98)
printl " MyUdt_1.MyStaticStringArray( 99):", MyUdt_1.MyStaticStringArray(99)
printl " MyUdt_1.MyStaticStringArray(100):", MyUdt_1.MyStaticStringArray(100)
printl string$(70, "-")
printl
waitkey