PDA

View Full Version : UDT 'ME' as parametter



DirectuX
26-10-2019, 16:49
Hi,

in my attempt to generalise the piece of code suggested by Petr (https://www.thinbasic.com/community/showthread.php?12974-STAT_CLONEARRAY-and-UDT), I've faced this error for which I didn't see the reason.

arrayclone1.tbasic.LastRunTimeError.ini

[Script]
Main=T:\_DEV\arrayclone1.tbasic
Include=
[RunTimeError]
DateTime=26/10/2019 16:31:40
Code=20
Description=Missing Close Parens ')'. Expected a ')' but found something else.
Line=27
LineCode=ME.ARRAYCLONE(ARR, ME.MYARRAY)
Token=ME
Additional=

10089


'---Script created on 10-26-2019 16:13:36 by
uses "Console"

type Vector3D
x as float32
y as float32
end type

type util

myarray() as Vector3d

function arrayClone(byref arr() as anytype, byref arr_copy() as Anytype)

redim arr_copy(ubound(arr))

'see https://www.thinbasic.com/community/showthread.php?12974-STAT_CLONEARRAY-and-UDT
' This is like "copy bytes from start of the array, of total length calculated like number-of-elements * size-of-element and store them to string"
' VarPtr is "variable pointer"
string binary = peek$(varptr(arr(1)), CountOf(arr(1))*SizeOf(arr(1)))
' This is like - "paste the binary string at place starting at beginning of arr_copy"
poke$(varptr(arr_copy(1)), binary)

end function

function SaveIt(arr() as Vector3d)
me.arrayClone(arr, me.myarray)
end function

end type

dim arr(3) as Vector3D
dim arr_copy(3) as Vector3D
dim test as util

int32 i

for i = 1 to ubound(arr)
arr(i).x = i
arr(i).y = i
next

test.SaveIt(arr)

printl "Source array:"
for i = 1 to ubound(arr)
printl arr(i).x, arr(i).y
next


printl


printl "Copied array:"
for i = 1 to ubound(arr)
printl test.myarray(i).x, test.myarray(i).y
next


waitkey