To avoid the more complicated solution where the frame calls some routine in the parent form so that the form can kill the frame… I was wondering if it’s OK to simply set the form as the frame’s parent, and let Delphi call Frame.Free when the user closes the application?
procedure TForm1.FormShow(Sender: TObject);
var
Frame2 : TFrame2;
begin
//Frame2 := TFrame2.Create(nil);
Frame2 := TFrame2.Create(Self);
Frame2.Align := alClient;
Frame2.Parent := Self;
Frame2.Visible := True;
end;
Thank you.
Actually you are confusing parent and owner:
The owner is passed as parameter to the constructor and will take care of freeing the component, the parent is the control which contains the control visually.
Example:
You have got a form, a panel on that form and a label on that panel:
The form usually is the owner of the panel and the label. The form is the parent of the panel and the panel is the parent of the label.
As for your question: It is perfectly OK to pass the form that contains the frame as the owner. When the form is freed, it will also free the frame. In addition you must set the parent to some other control for the frame to become visible. That can of course also be the form, but this will not have any effect on freeing the frame.