delphi - Delphi 无法从 VertScrollBox 中删除子级
问题描述
我有一个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;
所以情况是这样的:
问题
当我按下另一个按钮时,我需要删除滚动机器人中的每个矩形,除了第一个。
我正在做相反的操作。为了做到这一点,我从 SO 中找到的答案中获取了代码,该答案指出我应该向后运行循环:
for j := VertScrollBox.ChildrenCount-1 downto 1 do
if (VertScrollBox.Children[j] is TRectangle) then
VertScrollBox.RemoveObject(VertScrollBox.Children[j]);
此代码不起作用,因为没有删除矩形。那是因为我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]);
未添加到 中Content
但添加到滚动框本身的对象类和特定对象实例是:
- F内容
- 资源链接
- TEffect 实例
- TAnimation 实例
- FVScrollInfo[0].Scroll
- FVScrollInfo[1].Scroll
- FHScrollInfo[0].Scroll
- FHScrollInfo[1].Scroll
- FSizeGrip
推荐阅读
- c# - can't get firebase_url in google-services.json
- javascript - Is there any reference mapping a function in react?
- google-tag-manager - Tag Fires but no Event in GA4
- animation - 如何在svg圆圈内制作波浪线动画
- c++ - SPIFFS 将返回键保存到字符串中
- perl - 从 HoA 值中获取独特元素并打印
- javascript - 当我点击其中一个元素时,所有元素都会消失,但只需要我没有点击的元素消失
- java - 更新 Android Studio 后 Gradle 无法正常工作
- arrays - 如何在菜单数组内的子菜单中过滤角色
- jquery - 在不使用日期选择器的情况下获取完整日历的第一个和最后一个可见日期