DELPHI가 여러 EDIT 컨트롤을 동적으로 생성 및 해제

4973 단어 Delphi
unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls;

 

type

  TForm1 = class(TForm)

    pnl1: TPanel;

    btn1: TButton;

    btn2: TButton;

    procedure btn1Click(Sender: TObject);

    procedure btn2Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

  editm:array of tedit;

 

implementation

 

{$R *.dfm}

 

//    EDIT  

procedure TForm1.btn1Click(Sender: TObject);

var

    i,d,j:integer;

begin

d:=0;

j:=3;

setlength(editm,j);

  for   i:=0   to   j-1   do

  begin

    editm[i]:=tedit.Create(self);

    editm[i].Parent:=pnl1;

    editm[i].Width:=120;

    editm[i].Height:=20;

    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+20;

  end;

end;

//     EDIT  

procedure TForm1.btn2Click(Sender: TObject);

var

  i:Integer;

begin

for i:=0 to 2 do

begin

editm[i].free;

end;

end;

 

end.

좋은 웹페이지 즐겨찾기