I have a TVertScrollBox
control with a TRectangle inside. When I click a button I take that rectangle and I copy it 20 times inside the scroll box.
// 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 the situation looks like this:
Problem
When I press another button I need to delete every rectangle in the scroll bot except the first one.
I am doing the reverse operation. In order to do this I have taken the code from an answer found in SO which states that I should run the loop backwards:
for j := VertScrollBox.ChildrenCount-1 downto 1 do
if (VertScrollBox.Children[j] is TRectangle) then
VertScrollBox.RemoveObject(VertScrollBox.Children[j]);
This code doesn't work because rectangles aren't deleted. Is that because I haven't set a Parent
for the rectangle when adding it?
I've also tried something like RemoveObject(TRectangleVertScrollBox.Children[j]))
but still nothing.
VertScrollBox.AddObject
method adds controls to the inner scroll box Content
control. You have to iterate through Content
children in order to remove added controls.
for j := VertScrollBox.Content.ChildrenCount-1 downto 1 do
if (VertScrollBox.Content.Children[j] is TRectangle) then
VertScrollBox.Content.RemoveObject(VertScrollBox.Content.Children[j]);
Object classes and particular object instances that are not added to the Content
, but to scroll box itself are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With