procedure TForm1.BitBtn1Click(Sender: TObject); var edt:TEdit; begin edt:=TEdit.Create(form1);///或TEdit.Create(self); Edt.Left:=10; edt.Top:=10; edt.Visible:=true; edt.Parent:=Form1;////放在Parent上面。没有也没关系,只要前面Create(form1),后面form1.findcomponent就能够找到 edt.Name:='edt'; end;procedure TForm1.BitBtn2Click(Sender: TObject); var cp:TComponent; begin cp:=form1.FindComponent('edt');//或self.FindComponent('edt');和前面create 对应 if cp<>nil then begin showmessage(TEdit(cp).Name); TEdit(cp).Destroy; end; end;
BCB中以下代码看看有没有帮助。Button1动态创建TEdit* edt取名为"edt"
Button2用FindComponent找到前面创建的edt并释放内存void __fastcall TForm1::Button1Click(TObject *Sender)
{
TEdit *edt = new TEdit(Form1);
edt->Left =10;
edt->Top=10;
edt->Parent = Form1;
edt->Visible = true;
edt->Name = "edt";}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
delete ((TEdit*)FindComponent("edt"));
}
//---------------------------------------------------------------------------
1:你确定你的代码中有显示的调用 ArrEdit[I].Name := 'Edit'+IntToStr(I); 这行代码???
if self.FindComponent(sName) <> Nil2:写一个事件,如TpubEdit.OnClick(Sender: TObject); 在其中写入行代码
ShowMessage((Sender as TEdit).Name);
然后在生成Edit时将其OnClick := pubEdit.OnClick;
调试下就知道了
begin
(FindComponent(CreateName) as TEdit).text:='就是me';
end;
动态创建Parent属性了吗?
var
edt:TEdit;
begin
edt:=TEdit.Create(form1);///或TEdit.Create(self);
Edt.Left:=10;
edt.Top:=10;
edt.Visible:=true;
edt.Parent:=Form1;////放在Parent上面。没有也没关系,只要前面Create(form1),后面form1.findcomponent就能够找到
edt.Name:='edt';
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
cp:TComponent;
begin
cp:=form1.FindComponent('edt');//或self.FindComponent('edt');和前面create 对应
if cp<>nil then
begin
showmessage(TEdit(cp).Name);
TEdit(cp).Destroy;
end;
end;