Your program's components are arranged in a hierarchy. In general, this hierarchy is used to keep track of which components should appear inside other components.
For example, the children of a
dialog box are those components which appear inside the dialog. When the dialog box becomes visible, NewBASIC knows that its children components should become visible. If the dialog is moved a few pixels to the left, the children components should move with it. If the dialog becomes invisible, so should its children components.
Consider the dialog box pictured to the right. When NewBASIC stores the various components that make up this dialog's gadgetry, it will keep track of them using a sort of hierarchy. A part of the hierarchy for the above dialog is shown below.
If component A is directly above component B in the hierarchy, we say that component A is component B's
parent
. We say that component B is component A's
child
, or one of component A's
children
.
While those components that can have children may have more than one each, a component may have only one parent.
There are properties corresponding to these ideas. To access a component's parent, use its parent property (see See parent component The component's parent component. ). To access a component's children, use its numChildren (see See numChildren integer (0-) This read-only property is the component's number of children. ) and children ( See children[] component This is a read-only array of components, this component's children. The numChildren property is the number of children. ) properties.
Not all components may have children. Only those components with children listed among their standard properties may have children. Some components may have a strange parent , or a null parent . Specifically, window components (Forms, Dialogs, and Floaters) have a strange parent; so do service components, which are components that never appear on-screen (some examples: Alarms, Busies, Databases, Timers.)
In the Builder, if you move a component into another component's visual bounds, the Builder will try to make the component you're moving a child of the other. If that doesn't work, the component you're moving may become the other component's sibling --the Builder may assign it the same parent.
In BASIC code, you specify a component's parent by means of its parent property:
Specify the parent of a newly created component, by means of the second argument to the MakeComponent() routine (see See parent component The component's parent component. ):
MyChoice = MakeComponent("choice", group1)
The MakeComponent() routine can take a special keyword to specify a special parent. If the parent is "app," that means that the new component should have no real parent; its only parent will be the application itself--which is not a component.
To find out if component A can be a parent of component B, use the ValidParent() built-in BASIC function (see See You may make one component the child of another in NewBuild by placing the child component within the parent component. ):
IF ValidParent( compA, compB ) THEN
compB.parent = compA
END IF
NewBASIC uses the parent/child hierarchy to make sure that certain things that happen to a parent will also happen to its children.