加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi无法从VertScrollBox中删除子项

发布时间:2020-12-15 04:14:37 所属栏目:大数据 来源:网络整理
导读:我有一个带有TRectangle的TVertScrollBox控件.当我点击一个按钮时,我取出那个矩形,然后在滚动框内复制20次. // var Rectangle: TRectangle;VertScrollBox.BeginUpdate;for i := 0 to 19 do begin //Copy the rectangle that is already inside the ScrollBox
我有一个带有TRectangle的TVertScrollBox控件.当我点击一个按钮时,我取出那个矩形,然后在滚动框内复制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;

所以情况看起来像这样:

问题

当我按下另一个按钮时,我需要删除除第一个之外的滚动机器人中的每个矩形.

我正在做相反的操作.为了做到这一点,我从SO中找到的答案中获取了代码,该答案表明我应该向后运行循环:

for j := VertScrollBox.ChildrenCount-1 downto 1 do
  if (VertScrollBox.Children[j] is TRectangle) then
    VertScrollBox.RemoveObject(VertScrollBox.Children[j]);

此代码不起作用,因为不删除矩形.那是因为我在添加矩形时没有为矩形设置父级吗?

我也尝试过类似RemoveObject(TRectangleVertScrollBox.Children [j])),但仍然没有.

解决方法

VertScrollBox.AddObject方法将控件添加到内部滚动框内容控件.您必须遍历内容子项才能删除添加的控件.
for j := VertScrollBox.Content.ChildrenCount-1 downto 1 do
  if (VertScrollBox.Content.Children[j] is TRectangle) then
    VertScrollBox.Content.RemoveObject(VertScrollBox.Content.Children[j]);

未添加到内容的对象类和特定对象实例,但滚动框本身是:

> FContent> ResourceLink> TEffect实例> TAnimation实例> FVScrollInfo [0].滚动> FVScrollInfo [1] .Scroll> FHScrollInfo [0] .Scroll> FHScrollInfo [1] .Scroll> FSizeGrip

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读