0

I am not sure if my coding is correct, so please correct if I am wrong. I have a custom component with an Image.

CustomPic = class(TPanel)
private
   Image : TImage;
public
   constructor Create(AOwner: TComponent); override;
....
end;

In my constructor I do the following:

constructor CustomPic.Create(AOwner: TComponent);
begin
    Image := TImage.Create(Self);
    Image.Parent := Self;
    AddObject(Image);
end

This all works fine. However, when I put my custom component on a form and hit alt+F12 and alt+F12 back to my form, I have an extra image on my form. Should I implement something in my destructor?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Christo
  • 411
  • 7
  • 27

1 Answers1

1

Offhand, I don't see anything wrong with the code you showed (what does AddObject(), though?). The TImage is owned by the component so it will be freed automatically when the component is freed. If you are seeing multiple images then there must be multiple components being created.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770