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;
  var
  i: Integer;
  obj: TFMXObject;
begin
  Result := False;
  //go throug all childs
  for i := 0 to sb.Content.ChildrenCount-1 do
  begin
    //is specific object class
    if sb.Content.Children.Items[i] is TCalloutRectangle then
    begin
      //find it by Tag
      if (sb.Content.Children.Items[i] as TCalloutRectangle).Tag = idx then
      begin
        obj := (sb.Content.Children.Items[i] as TCalloutRectangle);
        sb.Content.RemoveObject(obj); //delete from parent
        Result := True;
        Break;
      end;
    end;
  end;
end;

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

Open in new window

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

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 ?
0
Sinisa VukSoftware architectCommented:
Is it on windows or android? Can you catch exception (try .. except ... showmessage .. end)?
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

dolphin KingAuthor Commented:
it is on android even try block did not catch any exception
0
dolphin KingAuthor Commented:
i believe this was fmx problem it self
0
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
0
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
Delphi

From novice to tech pro — start learning today.