Freeing dynamically-created controls in Android

  

In my Firemonkey multi-platform app, I dynamically create some controls. After using them, I destroy them.
In Windows, there is no issue with this dynamically created and destroyed process. However, it seems that in Android, the code below does not destroy the controls as an error will popup to say that the Control already exists (and I do see the old controls are still there when I try to re-create the controls).
How do I ensure the controls are destroyed properly in Android (and/or iOS – I assume it’s similar for iOS)?
for i := oParentRect.ControlsCount-1 downto 0 do
begin
oControl := oParentRect.Controls[i];
if (oControl is TText)
or (oControl is TEdit)
then
begin
FreeAndNil( oControl );
// I have also tried oControl.Free;
end;
end;

Comments are closed.