Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi Form ownership

Posted on 2016-09-03
4
Medium Priority
?
246 Views
Last Modified: 2016-09-22
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) ?
0
Comment
Question by:Sunsales
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 41783248
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

1
 

Author Comment

by:Sunsales
ID: 41783301
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?
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 2000 total points
ID: 41783587
there is no point in maintaining your own list
all components create with an owner are stored inside the parent container component
delphi does by default what you ask

except ... when you create components/forms with nil as owner
SubForm := TSubForm.Create(nil);

an object instance which is freed doens't have an owner
it just doesn't exist anymore

mind the difference between closing/hiding and free a form
1
 

Author Closing Comment

by:Sunsales
ID: 41811427
Thanx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question