We use the Parent property to get or set the parent of the control. The parent of a control is the control that contains it. For example, if an application includes three radio buttons in a group box, the group box is the parent of the three radio buttons, and the radio buttons are the child controls of the group box.
To serve as a parent, a control must be an instance of a TWinControl descendant.
When creating a new control at run time, assign a Parent property value for the new control. Usually, this is a form, panel, group box, or a control that is designed to contain another. Changing the parent of a control moves the control onscreen so that it is displayed within the new parent. When the parent control moves, the child moves with the parent.
Some controls (such as ActiveX controls) are contained in native windows rather than in a parent VCL control. For these controls, the value of Parent is nil (Delphi) or NULL (C++) and the ParentWindow property specifies the window.
Note: The Parent property declared in TControl is similar to the Owner property declared in TComponent, in that the Parent of a control frees the control just as the Owner of a component frees that component. However, the Parent of a control is always a windowed control that visually contains the control, and is responsible for writing the control to a stream when the form is saved. The Owner of a component is the component that was passed as a parameter in the constructor and, if assigned, initiates the process of saving all objects (including the control and its parent) when the form is saved.
Here is the working example of the implementation of Parent in the main panel creation:
1 2 3 |
# Main panel creation pnlMain = CreateComponent('TPanel',Owner) pnlMain.SetProps(Parent=self, Caption="",align = "alClient", Name = "MainPanel") |
Here is the working example of the implementation of Parent in the page control creation:
1 2 3 4 5 |
# Page control creation pgConMain = PageControl(pnlMain) pgConMain.Name = "MyPageControl" pgConMain.Parent = pnlMain pgConMain.Align = "alClient" |
Here is the working example of the implementation of Parent in the label creation:
1 2 3 4 5 6 7 8 9 |
# Label creation lblHello = CreateComponent('TLabel',pgOne) lblHello.Parent = pgOne lblHello.Caption = 'FirstName' lblHello.Name = 'Name' lblHello.Left = 20 lblHello.Top = 14 lblHello.Width = 121 lblHello.Height = 30 |
Here is the working example of the implementation of Parent in the edit box creation:
1 2 3 4 5 6 7 8 9 |
# Edit box creation edtHello = CreateComponent('TEdit',pgOne) edtHello.Parent = pgOne edtHello.Text = 'Jim' edtHello.Name = 'edtFirstName' edtHello.Left = 145 edtHello.Top = 14 edtHello.Width = 121 edtHello.Height = 30 |
Here is the working example of the implementation of Parent in the check box creation:
1 2 3 4 5 6 |
# Check box creation chkSingle = CheckBox(self) chkSingle.Parent = pgOne chkSingle.Caption = 'Single ?' chkSingle.Alignment = 'taLeftJustify' chkSingle.SetBounds(20, 44, 141, 30) |
Here is the working example of the implementation of Parent in the list box creation:
1 2 3 4 5 6 7 8 |
# List box creation lboxCountry = ListBox(pgOne) lboxCountry.SetProps(Parent=pgOne) lboxCountry.SetBounds(145,88,121,60) lboxCountry.Items.Add('RUSSIA') lboxCountry.Items.Add('USA') lboxCountry.Items.Add('INDIA') lboxCountry.Items.Add('AUSTRALIA') |
Here is the working example of the implementation of Parent in the datetime creation:
1 2 3 4 |
# Date time picker creation dtpDateofIssue = CreateComponent('TDateTimePicker',pgOne) dtpDateofIssue.SetProps(Parent=pgOne) dtpDateofIssue.SetBounds(145,162,121,30) |
Here is the working example of the implementation of Parent in the combo box creation:
1 2 3 4 5 6 7 8 |
# Combobox creation cbxCity = ComboBox(pgOne) cbxCity.SetProps(Parent=pgOne,Name='ComboBox') cbxCity.SetBounds(145,206,121,60) cbxCity.Items.Add('New York') cbxCity.Items.Add('Sydney') cbxCity.Items.Add('Banglore') cbxCity.Items.Add('Tokyo') |
Here is the working example of the implementation of Parent in the radiogroup creation:
1 2 3 4 5 6 |
# Radiogroup creation rbgRadioBox = RadioGroup(pgOne) rbgRadioBox.SetProps(Parent=pgOne,Caption='Gender') rbgRadioBox.SetBounds(20,250,242,90) rbgRadioBox.Items.Add('Male') rbgRadioBox.Items.Add('Female') |
Here is the working example of the implementation of Parent in the button creation:
1 2 3 4 |
# Button creation btnOK = Button(pgOne) btnOK.SetProps(Parent=pgOne,Caption = 'Submit',Name = 'btnOK') btnOK.SetBounds(145,540,60,30) |
Here is the working example of the implementation of Parent in the memo creation:
1 2 3 4 |
# Memo creation memoEvent = Memo(pgOne) memoEvent.SetProps(Parent=pgOne) memoEvent.SetBounds(300,14,350,300) |
Here is the working example of the implementation of Parent in the shape creation:
1 2 3 4 |
# Rectangle shape creation shpRectangle = Shape(pgTwo) shpRectangle.SetProps(Parent=pgTwo,Shape = 'stRectangle') shpRectangle.SetBounds(140,14,400,200) |
Here is the working example of the implementation of Parent in the color box creation:
1 2 3 4 |
# Colorbox creation clbSelect = ColorBox(pgTwo) clbSelect.SetProps(Parent=pgTwo) clbSelect.SetBounds(20,14,100,30) |
Here is the working example of the implementation of Parent in the draw grid creation:
1 2 3 4 |
# Draw grid creation grdTest = DrawGrid(pgTwo) grdTest.Parent = pgTwo grdTest.SetBounds(20, 220, 520, 180) |
Check out DelphiVCL which easily allows you to build GUIs for Windows using Python.