
Originally Posted by
kcvinu
@Rene Miner,
I am sorry, I didn't get you. I am confused about "SetAt". What is it used for ? To set a pointer at new memory location ?
SetAt will place a virtual variable to another position
GetAt will retrieve the current position
IF you
Dim x Like myObject.typename$ At myObject.DataPtr
' now x will let you access myObject
' and if you have another object of the same type:
if myOtherObject.typename$ = myObject.typename$ then
setAt(x, myOtherObject.DataPtr)
' now x is myOtherObject
endif
'if you have an array/string/heap of dataptrs that point to objects
'lets say
String sPtrs= mkDWD$(ptr1, ptr2, ptr3)
' easy to append more:
sPtrs &= mkdwd$(ptr4, ptr5)
store them to a heap
Dword pMyHeap=Heap_AllocByStr(sPtrs)
' append more?
Heap_Set(pMyHeap, Heap_Get(pMyHeap) & mkdwd$(ptr7, ptr8,...))
'you could set a surfing-dword at the first or last one
Local surfer as Dword at pMyHeap
' (or at Heap_End(pMyHeap -3) to go backwards)
repeat
' do something with the object the surfer points now
' will be one of ptr1, ptr2, ptr3 etc.
' then push the surfer forward
SetAt(Surfer, GetAt(Surfer) + SizeOf(Surfer) )
' - SizeOf... to go backward
until getAt(Surfer)>= Heap_End(pMyHeap)
' < pMyHeap if backwards
this allows to iterate through an array. if the array is pointers (Dword) then the pointers can point different types,
its like an array where any member can be of another type
And
Sub DoSomethingWith(byval pData as dword, byval sTypename as string)
Local X LIKE sTypename at pData
x.doSomething()
End Sub
lets you call same named functions on different types