Components(Index: Integer): IComponent;
Index. Index of the component requiring a link.
The Components property returns the child property, which index is passed by the input parameter.
Executing the example requires a form and any components on it. The OnCreate event handler is created for the form.
Class TESTForm: Form
//...
//List of the form components
//...
Sub TESTFormOnCreate(Sender: Object; Args: IEventArgs);
Begin
//Prepare components for form working
PrepareComponents(Self);
End Sub TESTFormOnCreate;
Sub PrepareComponents(Component: IComponent);
Var
i: Integer;
ChildComponent: IComponent;
Begin
For i := 0 To Component.ComponentCount - 1 Do
ChildComponent := Component.Components(i);
//In Tag index of the component is written according to its parent component
ChildComponent.Tag := i;
//If the component is the button, then write it to the BtnOnClick event
If ChildComponent Is Button Then
(ChildComponent As Button).OnClick := BtnOnClick;
End If;
ChildComponent.Data := GuidGenerator.Generate;
//If the component is the container for other components, then prepare them recursively
If ChildComponent.ComponentCount > 0 Then
PrepareComponents(ChildComponent);
End If;
End For;
End Sub PrepareComponents;
Sub BtnOnClick(Sender: Object; Args: IMouseEventArgs);
Begin
End Sub BtnOnClick;
End Class TESTForm;
On starting the form, recursive iteration of all components and setting of base properties are executed: the sequence number of the component towards the parent component is stored in the Tag property; unique global identifier is generated for each component in the Data property. All buttons will also be subscribed to the BtnOnClick general event.
See also: