how can i delete one control based on its tagstring ?

I had this question after viewing Tvertscrollbox like a whatsapp layout delete messages.

this answer shows how to delete all CR := TCalloutRectangle inside Vertscrollbox

i wanted to delete only one TCalloutRectangle based on its tag string how can i do that ?
dolphin KingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
My example set Tag property of . So to delete by Tab I make function ...
  CR := TCalloutRectangle.Create(VSB);
  CR.Tag := iTagID;

function DeleteCallout(sb: TVertScrollBox; idx: Integer): Boolean;
  i: Integer;
  obj: TFMXObject;
  Result := False;
  //go throug all childs
  for i := 0 to sb.Content.ChildrenCount-1 do
    //is specific object class
    if sb.Content.Children.Items[i] is TCalloutRectangle then
      //find it by Tag
      if (sb.Content.Children.Items[i] as TCalloutRectangle).Tag = idx then
        obj := (sb.Content.Children.Items[i] as TCalloutRectangle);
        sb.Content.RemoveObject(obj); //delete from parent
        Result := True;

procedure TForm1.Button6Click(Sender: TObject);
  DeleteCallout(VSB, 1);

Open in new window

... but you can check for string content (of child component) too.... I don't know what your tag string is ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dolphin KingAuthor Commented:
why when i delete some times app crashes ?
Sinisa VukSoftware architectCommented:
Is it on windows or android? Can you catch exception (try .. except ... showmessage .. end)?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

dolphin KingAuthor Commented:
it is on android even try block did not catch any exception
dolphin KingAuthor Commented:
i believe this was fmx problem it self
Geert GOracle dbaCommented:
when you delete something always use a reverse loop ...

  for i := count-1 downto 0 do 
    // delete stuff

Open in new window

otherwise the counter goes beyond the end point
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.