Structure Questions: struct in struct and constants in struct


I have two questions about the structures I could not answer until now:
-Can I add a field to a structure of type structure? (structure in structure)
Tried to insert a second, existing structure, into the first structure without success.

-Can I use constants somehow in structures for array defintions like: fieldname(MYCONSTANT) As Int32 ?
Tried to use a constant, defined as number, to use in a structure without sucess.

Sorry if I answer with another question but, why you use structures?
I mean that structs are sometimes useful when you have to interface to some external libraries with declares. Other than that, I strongly suggest you to make a new class and use this as a well organized container for data. Structs are more useful in C where there is no OOP

Hi Massimo

It’s exactly my problem, I have to communicate over UDP with application written in C. This application sends me structs. But I use a class to get all the data out of the struct.

And both questions are just to make my struct more readable and flexible. Everything works.

Answering to your questions:

  1. yes you can. Suppose you defined a structure named MyStruct, you can then include a field in another structure, defined as: aField as MyStruct

  2. no I think you can’t. But I’m not sure about this, perhaps a way exists.

  1. Oh, your right with a struct in a struct. I tested the must have mistyped myself well. Thank you very much Massimo!

  2. Okay.

Be warned that Xojo structs doesn’t support all features of C structs. For example you can’t have variable lengths and pointers to another struct are not easy.
In past I found myself not being able to go further with some declares because of these differences.
The alternative way is to use MemoryBlocks, though this is a PITA.