Parent/Child Type Structuring

Blitz3D Forums/Blitz3D Programming/Parent/Child Type Structuring

Use Stevie Gs method or there are a couple of other ways to go:

Manage the type list yourself using sibling and child links.
Type GADGET
	Field GID% ; Gadget ID
	Field GIMAGE$ ; Image
	Field GX% ; X Pos
	Field GY% ; Y Pos
	Field GW% ; Gadget Width
	Field GH% ; Gadget Height

	Field firstchild.GADGET	;link to first child of this gadget
	Field prv.GADGET	;link to previous sibling
	Field nxt.GADGET	;link to next sibling
	;Field parent.GADGET	;optional link to parent of this GADGET
End Type
This method is very good, but can be a little fiddly.

Next method is to allow a maximum number of children using a Constant, and store the children in a Blitz array:
Const MAXGADGETCHILDREN = 20
Type GADGET
	Field GID% ; Gadget ID
	Field GIMAGE$ ; Image
	Field GX% ; X Pos
	Field GY% ; Y Pos
	Field GW% ; Gadget Width
	Field GH% ; Gadget Height

	Field child.GADGET[MAXGADGETCHILDREN]
End Type


Another way is to store the Handle of the childrens Type objects in a bank (with an offset of 4 bytes between each).
Type GADGET
	Field GID% ; Gadget ID
	Field GIMAGE$ ; Image
	Field GX% ; X Pos
	Field GY% ; Y Pos
	Field GW% ; Gadget Width
	Field GH% ; Gadget Height

	Field childbank	;created using CreateBank()
End Type
For this one look up CreateBank(), and then Object() and Handle() on this forum.
Object/Handle primer
Interesting use of Object/Handle