Remove components at runtime in Delphi with Android

1

When creating a TButton dynamically at run time inside a TVertScrollBox. When I need to delete this button it will not disappear from the screen. This problem only occurs by running the application on Android (Windows works correctly).

To delete the buttons created at runtime inside the TVertScrollBox I execute this routine:

   for i := vsScroll.ComponentCount-1 downto 0 do
      if vsScroll.Components[i] is TButton then
         TButton(vsScroll.Components[i]).Free;

How do I remove the created components?

NOTE: It's no use using TButton(vsScroll.Components[i]).Destroy instead of Free .

    
asked by anonymous 15.11.2017 / 02:48

1 answer

1

I've solved it. For Android the memory component release function and consequent screen deletion is DisposeOf and not Free , as I used to use in VCL components.

Delphi Help says the following:

DisposeOf forces the execution of the destructor code in an object. The new Delphi mobile compilers introduces a new dispose pattern implemented by calling DisposeOf, which executes the destructor code even if there are variables with pending references to the object. After the DisposeOf method is called, the object is placed in a special state, the Disposed state. This means that the destructor is not called again if DisposeOf is called again, or if the reference count is zero (the moment in which the memory is released).

The routine to exclude components from my list created at runtime looks like this:

   for i := vsScroll.ComponentCount-1 downto 0 do
      if vsScroll.Components[i] is TButton then
         TButton(vsScroll.Components[i]).DisposeOf;
    
15.11.2017 / 19:44