ShowMessage(panel.ComponentCount.ToString);
ShowMessage(panel.ControlCount.ToString);
componetcount怎么与 controlcount不一样
ShowMessage(panel.ControlCount.ToString);
componetcount怎么与 controlcount不一样
procedure TForm4.btn4Click(Sender: TObject);
var
I: Integer;
begin
//测试ControlCount
with TButton.Create(pnl1) do
begin
Parent := pnl1;
end;
with TButton.Create(pnl1) do
begin
Parent := Self;
end;
with TButton.Create(Self) do
begin
Parent := Self;
end;
with TButton.Create(Self) do
begin
Parent := pnl1;
end;
ShowMessage(pnl1.ControlCount.ToString);//结果是2
ShowMessage(pnl1.ComponentCount.ToString);//结果是2 //我的错误结论:
//xxx.ControlCount --- 算的是 Owner 是xxx , parent也为xxx的 且是可视控件
//xxx.ComponentCount --- 算的是 owner 是xxx, parent为任何的组件(包含可视与非可视控件) //我师傅的正确结论死记:
// controlcount与owner无关
// 只与parent有关
// ComponentCount 与parent无关 只与 owner有关
end;
pnl2中 包含一个 btn23和 pnl3
pnl3中包含一个 btn24
pnl3中包含一个 btn24