Home > Back-end >  How do I remove a dynamic control?
How do I remove a dynamic control?

Time:10-04

The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ExtCtrls ComCtrls;

Type
TForm1=class (TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
For: TButton;
Button2: TButton;
Procedure Button1Click (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;
Sp1: tshape;

Implementation

{$R *. DFM}

Procedure TForm1. Button1Click (Sender: TObject);
The begin
Sp1:=tshape. Create (nil);
Sp1. Parent:=form1. PageControl1. Pages [0].
Sp1. Name:='aaaa';
end;

Procedure TForm1. Button2Click (Sender: TObject);
Var sp1: tshape;
The begin
Tshape (form1. PageControl1. Pages [0]. FindChildControl (" aaaa ")). Destroy;
//sp1. Destroy;
end;

End.


Click for the dynamically generated a tshape, click delete the tshape always make mistake when button2 ~ ~ how to achieve??
Trouble masters action you ~ ~ ~ ~ such as online

CodePudding user response:

Supplement: is how to according to create the NAME to delete this control ~ ~

CodePudding user response:

Control name. Not free

CodePudding user response:

FindChildControl can only find TWinControl and its subclasses, TShape not TWinControl subclasses, find out is nil, and of course, an
Can use PageControl1. Pages [0]. Controls [] traversal

CodePudding user response:

reference LGHT reply: 3/f
FindChildControl can only find TWinControl and its subclasses, and not TShape TWinControl subclasses, find out is nil, and of course, an
Can use PageControl1. Pages [0]. Controls [] traversal

Use FindComponent can also

CodePudding user response:

Remember you name or Handle dynamically created controls and use FindComponent to free fall, built by the time to record the name of the building or Handle, or how to find you!

CodePudding user response:

Direct Free ~ ~

CodePudding user response:

freeandnil

CodePudding user response:

Error should be not found

CodePudding user response:

To establish a handle to a save array, save the dynamic control in the name of the handle, handle, designated by the data again Free operation,
  • Related