Link to home
Start Free TrialLog in
Avatar of Paer Toernell
Paer ToernellFlag for Thailand

asked on

Delphi Form ownership

I want to create multiple instances of a (sub)Tform  that all are owned by another (main)Tform from where they where created. If the user closes a (sub)form, it should be destroyed and not be owned by the mainform. If the Mainform is closed, all subforms should all be destroyed. I guess i can do this with a new TComonentlist, but is there any functionality in the form that i can use? (probably also a TComonentlist) ?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Delphi's Ownership handle such things....
So... create forms under Main Form ownership .... and on sub form destroy - Main form will be notified... and sub form will be excluded from component list...
//main form
procedure TfrmMain.StartSubForm();
var
  childform: TSubForm;
begin
   childform := TSubForm.Create(frmMain);
   childform.Show; //show and do not block main form
end;

Open in new window


Child form's OnClose event:
procedure TSubForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Self.Hide;
  Action:=caFree;  //sub form want to be free.....
end;

Open in new window

Avatar of Paer Toernell

ASKER

Can I use a TobjectList instead of the Tform as owner and still get an automatic delete in the TobjectList  when i free the form?
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx