UnitUnit1;Interface usesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrls;typeTForm1=class(tform) Pnl1:tpanel; Btn1:tbutton; Btn2:tbutton; procedureBtn1click (Sender:tobject); procedureBtn2click (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End; varForm1:tform1; EDITM:Array ofTedit;Implementation {$R *.DFM} //dynamically creating Edit controlsprocedureTform1.btn1click (sender:tobject);varI,d,j:integer;beginD:=0; J:=3; SetLength (EDITM,J); fori:=0 toJ-1 Do beginEditm[i]:=Tedit. Create (self); Editm[i]. Parent:=PNL1; Editm[i]. Width:= -; Editm[i]. Height:= -; Editm[i]. Left:=0; Editm[i]. Top:=0+D; Editm[i]. Name:='Edit'+IntToStr (i); Editm[i]. Text:='Edit'+IntToStr (i); Editm[i]. Visible:=true; D:=d+ -; End;End;//destroying the created edit controlprocedureTform1.btn2click (sender:tobject);varI:integer;begin fori:=0 to 2 DobeginEditm[i].free;End;End; End.
DELPHI dynamically creates and releases multiple EDIT controls