View Full Version : Type pointer var not supported by WITH?
Michael Hartlef
24-09-2008, 08:55
Hi Eros,
I'm sure if it is a bug or just a feature. Does the WITH command not support Pointer variables?
Michael
Michael Hartlef
24-09-2008, 09:05
Nevermind, it works. Was again a stupid mistake by me.
Petr Schreiber
24-09-2008, 09:06
Hi Mike,
how do you create pointer variable? :-[
Petr
Michael Hartlef
24-09-2008, 09:12
Hi Petr,
here is some code:
' Empty ThinBASIC GUI file template
type testtype
id as long
end type
dim mytype as testtype
dim ptype as testtype ptr
dim ptype2 as testtype ptr
setat(ptype, varptr(mytype))
mytype.id = 1
msgbox(0,"mytype.id = " & mytype.id)
ptype.id = 2
msgbox(0,"mytype.id = " & mytype.id)
with pType
.id = 3
end with
msgbox(0,"mytype.id = " & mytype.id)
pType2 = heap_alloc(sizeof(testtype))
pType2.id = 40
msgbox(0,"pType2.id = " & pType2.id)
with pType2
.id = 50
end with
msgbox(0,"pType2.id = " & pType2.id)
myfunc()
heap_free(pType2)
function myfunc() as long
with pType2
.id = 60
end with
msgbox(0,"pType2.id = " & pType2.id)
end function
Petr Schreiber
24-09-2008, 09:19
Hi Mike,
thanks :)
I think the pointers to other than UDTs are not supported now as "data type" ( but you can use DWORDs to store values of VARPTR ).
I think referencing UDT variable without parameter returns pointer as well, maybe Eros will put more light on this.
Petr
ErosOlmi
24-09-2008, 10:41
Unfortunately pointers are partially handled by thinBasic.
The best and most secure way for the moment is to define LONG variables to be used as pointers and allocate memory. That use DIM ... AT to allocate dynamic virtual structures at some location. At that point vitual variables will be like standard variables and you will be able to use WITH clause.
I do not think I will have enough time to improve current situation for the next thinBasic release.
Eros
Michael Hartlef
24-09-2008, 13:49
There is nothing wrong Eros. I had made a mistake and thought the WITH command didn't support PTR variables to UDT's. But it does and so everything is fine.
ErosOlmi
24-09-2008, 14:12
I'm happy Michael :D
But I know I have to improve PTR a lot ;)
I have thinCore code under my eyes every day ...
Michael Hartlef
24-09-2008, 15:35
Right now I'm really twisting and turning UDT's with allocated memory and Linked Lists inside out. That is why I need the pointer. One thing is AStar path finding and the other one is a OpenGL GUI. So far everything works fine. Linked lists could be faster but it is still a good performance.
ErosOlmi
24-09-2008, 15:42
Michael,
I'm currently rewriting LL module from scratch keeping the same syntax ;)
I'm adding a 2 layer system in such a way there will never problems when deleting LL elements. I hope to be able to add also more speed. Some LL functions uses serial searching. I was thinking to create a LL with hash table to be able to find elements much faster but I'm not sure so far. I will keep you updated.
Ciao
Eros