# Assigning Structure address?

**URL:** <https://forum.xojo.com/t/assigning-structure-address/50876>\
**Category:** General\
**Created:** [October 25, 2019, 6:33pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876 "2019-10-25T18:33:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [October 25, 2019, 6:33pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/1 "2019-10-25T18:33:31Z")

</div>

I’ve not done much beyond very simple stuff with declares, structures or pointers, so please forgive me if this is a stupid question!

if a declare returns a pointer to an array of n structures , as well as the number of structures in the array, and I have defined a Xojo structure for the array elements, can the starting address of of an Xojo structure variable be assigned somehow so i can iterate over the array using the xojo structure?

Usually you pass the Xojo structure variable byRef to the declare, but that obviously would not work for an array…If the # array elements were know at design time creating a Xojo Structure with an Array of structures would be the obvious solutions… but that is not the case…

I could use a memory block but that is a more code , less readable and just plain messy… Alternatively I could copy the correct #of bytes for each each structure in the array to the Xojo structure variable from a memoryblock … but I always hate copying data that should not need to be copied

What I want to be able to do, is something like this if possible:

[code]DIM aStruct as MyStruct  
DIM ubStructArray as integer = UBoundArrayElementsFromDeclare  
DIM PtrToArray as Ptr = FromDeclare

For i as integer = 0 to ubStructArray  
aStruct.Address = PtrToArray  
PtrToArray = PtrToArray + aStruct.Size  
’ Process the data  
Next  
[/code]

but i don’t know if it is possible to assign an address to a Xojo Structure variable, or if it is, how to do it.

Thanks,  
-Karen

---

<div class="post-metadata">

**Author:** ![Norman\_Palardy](https://forum.xojo.com/user_avatar/forum.xojo.com/norman_palardy/32/169_2.png) [@Norman\_Palardy](https://forum.xojo.com/u/Norman_Palardy)\
**Post date:** [October 25, 2019, 6:36pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/2 "2019-10-25T18:36:45Z")

</div>

you should be able to using a technique like this  
[https://www.great-white-software.com/blog/2019/07/16/c-unions/](https://www.great-white-software.com/blog/2019/07/16/c-unions/)

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [October 25, 2019, 6:55pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/3 "2019-10-25T18:55:48Z")

</div>

Thanks Norm!!!

Either I missed it or the language reference on Ptr nor Structure never says that you can do:

DIM aStructVar as MyStruct = aPtr.MyStruct

So then my code would be:

[code]DIM aStruct as MyStruct  
DIM ubStructArray as integer = UBoundArrayElementsFromDeclare  
DIM PtrToArray as Ptr = FromDeclare

For i as integer = 0 to ubStructArray  
aStruct = PtrToArray.MyStruct  
PtrToArray = PtrToArray + aStruct.Size  
’ Process the data  
Next[/code]

This definitely should be in the docs!!!

---

<div class="post-metadata">

**Author:** ![Norman\_Palardy](https://forum.xojo.com/user_avatar/forum.xojo.com/norman_palardy/32/169_2.png) [@Norman\_Palardy](https://forum.xojo.com/u/Norman_Palardy)\
**Post date:** [October 25, 2019, 7:37pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/4 "2019-10-25T19:37:38Z")

</div>

It should be but I dont think this capability has ever been well understood by anyone writing the docs so it goes under documented  
Thats been true for a long time though - long before docs became Pauls job

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [October 25, 2019, 9:13pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/5 "2019-10-25T21:13:55Z")

</div>

\<[https://xojo.com/issue/58030](https://xojo.com/issue/58030)\>

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:08pm UTC](https://forum.xojo.com/t/assigning-structure-address/50876/6 "2021-04-29T16:08:50Z")

</div>


