How to destroy a control in a form ? lazarus / 13-General ---------------------------------------------------------------------- ben.san · 2007-01-14 15:28 How do you destroy a control in a form. I guess MyContol.Parent:=nil or RemoveControl(Mycontrol) will remove it visually but won't destroy it. When I try MyControl.Free (after the previous instructions) it generates an exception. So how do you destroy it. Benoit ---------------------------------------------------------------------- Zomis · 2007-01-14 19:23 Why would you want to destroy it? All controls placed on your form gets destroyed automatically when the program ends. Using MyControl.Parent:=nil is not something I would use, but I'm not sure what to use that for. But to destroy a control, you should use MyControl.Free (no need to do any other instructions, like setting Parent to Nil or calling RemoveControl). ---------------------------------------------------------------------- ben.san · 2007-01-25 22:17 Actually, I need it because I'm writting a dynamic interface where controls may be added and removed at runtime. For example, I may have to add a panel and the make it disappear. It seems natural to want to destroy it, just to save memory ! But as I said, calling MyControl.Free will raise an exception. Try it and you'll see. (or my Lazarus is being espacally nasty with me...) ---------------------------------------------------------------------- Zorba · 2007-01-26 02:16 Try this (from parent down): Parent.MyControl.free; For example destroy Edit1 on Form1: Form1.Edit1.Free; No problems here with this. ---------------------------------------------------------------------- felipemdc · 2007-01-26 02:19 Maybe it´s a platform specific problem. Which platform are you using?