I would guess a "memoryleak" or something other weird happening in your code, could be anywhere.

Did you try panel1.parent := frame in form's onDestroy event? Still, even if it works like that it doesn't change the fact there is a serious error in your code that could alter something else later or make program crash on runtime.