RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TWinControl.RemoveControl Method

Removes a specified control from the Controls array.

Pascal
procedure RemoveControl(AControl: TControl);
C++
__fastcall RemoveControl(TControl * AControl);

RemoveControl removes a child control from the Controls property. After calling RemoveControl, the control is no longer the parent of the child specified by the AControl parameter.  

Applications should not call RemoveControl directly. Child controls are automatically inserted and removed when added or deleted at design time. At runtime, use the Parent property of the child control to remove it from the Controls array.  

C++ Examples: 

 

/*
This example uses a button placed next to a group box. When the
user clicks the button, the group box becomes the parent of the
button, so the button moves inside the group box.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (Button1->Parent != GroupBox1) // second click?
  {
    RemoveControl(Button1);
    GroupBox1->InsertControl(Button1);
  }
}

/*
Note that it was necessary to remove the button from the Controls
property of the form before the button actually moves into the
group box. This code accomplishes the same thing:
*/

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Button2->Parent = GroupBox1;
}

 

Delphi Examples: 

{
This example uses a button placed next to a group box. When the
user clicks the button, the group box becomes the parent of the
button, so the button moves inside the group box.
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  if (Button1.Parent <> GroupBox1) then // second click?
  begin
    RemoveControl(Button1);
    GroupBox1.InsertControl(Button1);
  end;
end;

{
Note that it was necessary to remove the button from the Controls
property of the form before the button actually moves into the
group box. This code accomplishes the same thing:
}

procedure TForm1.Button2Click(Sender: TObject);
begin
  Button2.Parent := GroupBox1;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!