Search code examples
delphifiremonkeydelphi-10.3-rioflowlayout

How to delete all items of a TFlowLayout at runtime?


I want to clear a FlowLayout at run time, is there a function to do that ? I thought about mapping all its items and free theme, but I don't know how to access its items, any code example please ?


Solution

  • Using the Children and ChildrenCount properties you can free the items, either in reverse order

    for i := FlowLayout1.ChildrenCount-1 downto 0 do
      FlowLayout1.Children[i].Free;
    

    or in forward order (repeatedly addressing item with index 0)

    for i := 0 to FlowLayout1.ChildrenCount-1 do
      FlowLayout1.Children[0].Free;