View Full Version : New feature very closed to be released
ErosOlmi
09-09-2006, 12:35
We are very excited about a new thinBasic feature we will release quite soon: possibility to pass arrays (of whatever type) and UDT (User defined Type) as parameters inside functions. This will give a lot of power to scripts.
Imagine you have an array of 1000 items and you need to manage it from inside a function. In current thinBasic version the only way to achieve it is to declare array as GLOBAL and access it in function. Now you can create the array where you need (GLOBAl or LOCAL to some other function) and pass it as BYREF parameter to another function. No data is copied, just reference are created.
The same apply when you need to pass a data structure. In current version it is not possible to pass an UDT to a function and the only ways is to declare a GLOBAL variable of that TYPE and use it inside the functions or pass to functions individual UDT elements as base data types (LONG, EXT, STRING, ...). Now you can pass the single UDT or even arrays of UDT to functions passing them as BYREF.
Our tests gave us good results. We need some more internal testing but we are confident we will be able to release it in few days.
More info will follow ...
ErosOlmi
09-09-2006, 12:48
A dummy example passing an UDT to a function, just to have a look:
'---Declare a new type
type MyType
s1 as string * 10
l1 as long
s2 as string * 20
l2 as long
end type
'---Allocate a new variable of that type
dim MyTypeVariable as MyType
'---Assign some data
MyTypeVariable.s1 = "Hello"
MyTypeVariable.s2 = "World"
'---See data before passing UDT to function
msgbox 0, MyTypeVariable.s1 & $crlf & _
MyTypeVariable.s2
'---Execute the function that will have a reference to MyTypeVariable
'---When UDT parameters a re declared, automatic BYREF passing is used
ChangeIt(MyTypeVariable)
'---Now show again to see what happened
msgbox 0, MyTypeVariable.s1 & $crlf & _
MyTypeVariable.s2
'---------------------------------------------
function ChangeIt(ReferencedUDT as MyType)
'---------------------------------------------
ReferencedUDT.s1 = "A123"
ReferencedUDT.s2 = "B456"
end function
ErosOlmi
09-09-2006, 12:51
Same example as above but now we pass an array of UDTs:
type MyType
s1 as string * 10
s2 as string * 20
l1 as long
l2 as long
end type
dim MyTypeVariable(10) as MyType
MyTypeVariable(1).s1 = "Hello"
MyTypeVariable(1).s2 = "World"
function ChangeIt(a() as MyType, Item as long)
a(Item).s1 = "A123"
a(Item).s2 = "B456"
end function
msgbox 0, MyTypeVariable(1).s1 & $crlf & _
MyTypeVariable(1).s2
ChangeIt(MyTypeVariable, 1)
msgbox 0, MyTypeVariable(1).s1 & $crlf & _
MyTypeVariable(1).s2
ErosOlmi
09-09-2006, 12:58
Another example now working on a multi dimension numeric array passed BYREF:
'---Create a numeric array and assign all its elements
'---a default value of 1
dim MyArray(10, 100) as long value 1
'---Show an element
msgbox 0, MyArray(10, 100)
'---Call the modifier function passing the whoole array
'---Arrays will be passed BYREF by default even if forced BYVAL
FillIt(MyArray)
'---Show again data to see what happened
msgbox 0, MyArray(10, 100)
'-----------------------------------------------------------
' To indicate you want to pass an array, just put a ()
' after the name of the parameter. Simple
function FillIt(InternalByRefArray() as long)
'-----------------------------------------------------------
dim X, Y as long
for X = 1 to ubound(InternalByRefArray(1)) '---First dimension
for Y = 1 to ubound(InternalByRefArray(2)) '---Second dimension
InternalByRefArray(X, Y) = X * Y '---Assign some dummy data
next
next
end function
ErosOlmi
13-09-2006, 01:04
OK, feature released with thinBasic preview version 1.0.11.0
catventure
13-09-2006, 14:45
Hi Eros,
I have new preview - the new featured examples above worked OK :)
Great stuff.
Also the tooltips working great now at last! Hoorah!
Big, Big Thanks for extended functionality on RichEdit. :)
I'm examining this carefully. A question: I've looked at your example functions for setting fg and bg color for text. If it's not too much trouble can you tell how to set/unset italic, bold and mainbackground color also?
Reason: I'm going to have fun incorporating into my adventure program to achieve more colorful text etc..
Terrific update and Well Done,
catventure
ErosOlmi
13-09-2006, 15:35
Catventure,
good. I've fixed many things in message pump. Tooltips are now ok due to that work. Also ComboBox and ListBox are OK now regarding message pump but I need to add some checking and real life examples.
Regarding Rich Edit control, you have to be patient for little time again. I'm developing specific richedit functions to set fonts, colors, size, and so on. The new example is not finished (it is not working) but it is just a starting script I will used to show how to work with rich edit.
So, give me some little more time and will make you happy on this side (I hope :) )
Ciao
Eros