PDA

View Full Version : ASSIGN error in UDT



DirectuX
17-06-2020, 08:29
' Minimal example

type ttest

myvar as Single
myvar2 as single

function _Create()
MsgBox 0, str$(assign(1.5, me.myvar)) ' error
'me.myvar2 = assign(2.5, me.myvar) ' error
End Function

End Type

dim testVar as ttest



unless I'm mistaken this is not reported in the list of known issues (https://thinbasic.github.io/book-thinbasic_user_defined_types/appendix-list-of-known-issues.html), so

who can confirm this code is correct ?

DirectuX
17-06-2020, 09:01
' Minimal example

type ttest

myvar as Single
myvar2 as single

function _Create()
MsgBox 0, str$(assign2(1.5, me.myvar)) ' error
'me.myvar2 = assign2(2.5, me.myvar) ' error
End Function

End Type

dim testVar as ttest

function Assign2(what as number, byref where as Number) as number 'error
where = what
Return where
End Function

My attempt to circumvent my problem is not working either. Can't I pass me.myvar by ref ?

Petr Schreiber
17-06-2020, 18:39
Hi DirectuX,

the issue is related to ME/UDT variable in general - it has a special handling and multiple cases are "to be implemented".

In all cases, the memory overlay DIM .. AT is the workaround which can be used:


type ttest

myvar as Single
myvar2 as single

function _Create()
dim help_myvar as single at varptr(me.myvar)
assign(1.5, help_myvar)

MsgBox 0, me.myvar
End Function

End Type

dim testVar as ttest


We will have a look how we can make ME to be treated the same way as other variables / UDTs.


Petr

DirectuX
17-06-2020, 22:17
We will have a look how we can make ME to be treated the same way as other variables / UDTs.


Petr

Thanks Petr, thanks Eros.