1
procedure TForm1.FormCreate(Sender: TObject);
begin
  imageIndex := 0;
end;

In Delphi XE7, I'm creating a TImage control at runtime this way (called from a button click event):

newImage := TImage.Create(Self);
Inc(imageIndex);
newImage.Tag := imageIndex;
newImage.Name := 'Image' + IntToStr(imageIndex);
newImage.Padding.Right := 20;
newImage.Parent := HorzScrollBox2;
newImage.Visible := True;
newImage.Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'test.jpg'));
newImage.Align := TAlignLayout.Left;
newImage.Width := 200;
newImage.OnGesture := OwnImageGesture;
newImage.touch.InteractiveGestures := [TInteractiveGesture.LongTap];
newImage.PopupMenu := pmIgame;

This is how I free a TImage object (called from a button click event):

FindComponent('Image1').Free;

When I run under Windows and create an object and free it, it works well. But when I run under Android device or emulator the TImage object is not released. I don't know why.

TLama
  • 75,147
  • 17
  • 214
  • 392
Lionking
  • 89
  • 1
  • 13
  • 2
    It would be so much cleaner to use arrays rather than `FindComponent`. I guess the answer to your question is to call `DisposeOf` rather than `Free`. – David Heffernan Jan 06 '15 at 11:32
  • 1
    possible duplicate of [How to free a component in Android / iOS](http://stackoverflow.com/questions/27818697/how-to-free-a-component-in-android-ios) – TLama Jan 14 '15 at 12:18
  • 1
    @DavidHeffernan I know this is a very old question, but when you say array, do you mean array of TImage objects. – ThN Apr 19 '23 at 13:55
  • @ThN Yes that's precisely it – David Heffernan Apr 19 '23 at 14:02

0 Answers0