我有一个TVertScrollBox带有TRectangle 的控件.当我点击一个按钮时,我取出那个矩形,然后在滚动框内复制20次.
// var Rectangle: TRectangle;
VertScrollBox.BeginUpdate;
for i := 0 to 19 do
begin
//Copy the rectangle that is already inside the ScrollBox
Rectangle:= TRectangle(RectangleTemplate.Clone(VertScrollBox));
VertScrollBox.AddObject(Rectangle);
end;
VertScrollBox.EndUpdate;
Run Code Online (Sandbox Code Playgroud)
所以情况看起来像这样:
问题
当我按下另一个按钮时,我需要删除除第一个之外的滚动机器人中的每个矩形.
我正在做相反的操作.为了做到这一点,我从SO中找到的答案中获取了代码,该答案表明我应该向后运行循环:
for j := VertScrollBox.ChildrenCount-1 downto 1 do
if (VertScrollBox.Children[j] is TRectangle) then
VertScrollBox.RemoveObject(VertScrollBox.Children[j]);
Run Code Online (Sandbox Code Playgroud)
此代码不起作用,因为不删除矩形.那是因为我Parent在添加时没有为矩形设置?
我也尝试了类似RemoveObject(TRectangleVertScrollBox.Children[j]))但仍然没有的东西.
VertScrollBox.AddObject方法将控件添加到内部滚动框Content控件.您必须遍历Content子项才能删除添加的控件.
for j := VertScrollBox.Content.ChildrenCount-1 downto 1 do
if (VertScrollBox.Content.Children[j] is TRectangle) then
VertScrollBox.Content.RemoveObject(VertScrollBox.Content.Children[j]);
Run Code Online (Sandbox Code Playgroud)
未添加Content到滚动框本身的对象类和特定对象实例是:
| 归档时间: |
|
| 查看次数: |
380 次 |
| 最近记录: |