Designable Surface - Root control |
Top Previous Next |
Root controls
The designable surface, where components can be laid out in design-time, is provided by a Root control which is to be referenced by the Root property of the Design Module component.
The Root control that must be a descendant of TWinControl. Two different cases are to be distinguished:
The rules which are to be obeyed in these cases while setting up the design environment, are presented in the table below.
Creating a custom Root control
Logic required for correct Root control behaviour is already implemented in Delphi forms, because they are used in Delphi designer, but it is not implemented in other standard VCL controls. So to create a custom Root control, the following steps are to be performed:
procedure TMyRoot.Notification(AComponent: TComponent; Operation: TOperation); var LForm: TCustomForm; begin inherited; LForm := GetParentForm(Self); if (LForm <> nil) and (LForm.Designer <> nil) then LForm.Designer.Notification(AComponent, Operation); end;
procedure TMyRoot.GetChildren(Proc: TGetChildProc; Root: TComponent); var I: Integer; OwnedComponent: TComponent; begin inherited GetChildren(Proc, Root); if Root = Self then for I := 0 to ComponentCount - 1 do begin OwnedComponent := Components[I]; if not OwnedComponent.HasParent then Proc(OwnedComponent); end; end;
Components on the Root's designable surface
When the root is designed, various components can be placed on it using designer or manually in code. If you add some components manually in code you should specify the root as an owner in component constructor call. Only components that are children of the root can be touched by designer or saved/loaded with the root.
Note that some VCL controls can be complex and actually contains more then one instance of TControl descendants. For example, TLabeledEdit actually combines two controls – TLabel and TEdit descendants. But, only main control (s) is design-aware. So, you, for example, will not be able to select edit label by designer.
Root with frames
Special rules exists for frames on the root and its children. See Working With Frames topic to learn how to design roots with frames. |