JasmineCorp Directory   
  
Usenet News Group Archives!!!

Usenet Groups:

 

 

 

 

 

Re: Create a new form dinamically so that ...
--------------------------------------------------------------------------------------------
Newsgroup: borland.public.cppbuilder.students
Posted by: JD
2006-12-19 17:17:14


kronos wrote:
>
> Do i have to call "delete Form2" in "OnClose" event of Form1?

No. In fact, you never have to explicitly delete it because you
assigned it's Owner as the main form when you did this:

Form2 = new TForm2( this );

the hidden 'this' pointer referes to what ever class it's used
in so in the main form it means 'Form1'.

How it works is that when an object is owned, it's placed into
it's Components array and then the Owner registers interest in
being notified if that object gets destroyed so that it can be
removed from the Components array. Now, when the main form is
destroyed, it itterates it's Components array and destroys
those objects first and as they are destroyed, the itterate
their components array and so on ad infinitum.

So, as long as you assign an Owner, you need not worry
about destroying the object unless you have a need to do
so dynamically for some other reason.

As a note, the Controls array works exactly the same way.
How Controls differs from Components is that Controls
represents the controls that an objects Parents (where it
lives on-screen). so an object can have a different Owner and
Parent. Destroy either of the 2 and that object will also be
destroyed.

> Anyway when i close Form2 Form2's distructor already
> deallocate the heap space preavoiusly occupy by Form2,
> doesn't it?

No, not even if you have assigned an OnClose event and set
the Action parameter to caFree. Deallocation of the form
under these circumstances is message based so the object
is still valid until the system hits an idle state (or you
call Application::ProcessMessages) and pending messages are
processed.

> in theory do i have to call delete Form2 only when i close
> Form1 before Form2, don't i?

You don't ever *have to* call it and you can call it when ever
where ever you like except from within Form2. A class can not
destroy itself this way because you'd be deleting a block of
memory where code is currently executing. The best out come
in this case would be an Access Violation.

> how i can keep open the second form (Form2) when i close the
> main form (Form1)?

You can not.

> Mozzilla Thundembird has this behaviour!

No it doesn't. Those 'windows' are seperate exe's.

You have 2 choices, make Form2 a seperate exe and spawn it
instead of dynamically allocating it or just hide the main
form and remove it from the taskbar but this approach has
issues with knowing when to actually close it.

~ JD

 

 

 

More >> 

Domain Registration:
.com .org .net
.info .biz .us