如下一段代码,
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
tmp_control:twincontrol;
Tmp_btn:Tbutton;
begin
i:=1;
Tmp_btn:=Tbutton.Create(nil);
Tmp_btn.Parent:=panel1;
Tmp_btn.Name:='Button'+inttostr(i+1);
showmessage(Tmp_btn.caption);
showmessage(tButton(FindComponent('Button'+inttostr(i+1))).caption);
end;为什么tButton(FindComponent('Button'+inttostr(i+1)))与Tmp_btn会不等。为什么在第二个showmessage弹出框中弹出的是空字串而不会与第一个SHOWMESSAGE弹出框中不等!
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
tmp_control:twincontrol;
Tmp_btn:Tbutton;
begin
i:=1;
Tmp_btn:=Tbutton.Create(nil);
Tmp_btn.Parent:=panel1;
Tmp_btn.Name:='Button'+inttostr(i+1);
showmessage(Tmp_btn.caption);
showmessage(tButton(FindComponent('Button'+inttostr(i+1))).caption);
end;为什么tButton(FindComponent('Button'+inttostr(i+1)))与Tmp_btn会不等。为什么在第二个showmessage弹出框中弹出的是空字串而不会与第一个SHOWMESSAGE弹出框中不等!
Tmp_btn:=Tbutton.Create(self);//---这样就会一样了。