Board index » delphi » MDI Parent Form Activities between Close and Destroy

MDI Parent Form Activities between Close and Destroy

What happens between an MDI form firing its OnClose and OnDestroy events?  I
ask, because I have a program that generates an Access Violation immediately
after the OnClose event of the main form if it has one or more MDI child
forms open when the application is closed, but generates no error if all of
the child windows are closed prior to closing the application.

I've tried running my code for closing all the windows by cycling through
the MDIChildren in the OnClose handler, but this doesn't prevent the Access
Violation.

Gabe Covert

 

Re:MDI Parent Form Activities between Close and Destroy


Quote
"Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message

news:3ebfc7af@newsgroups.borland.com...

Quote
> What happens between an MDI form firing its OnClose and OnDestroy events?
I
> ask, because I have a program that generates an Access Violation
immediately
> after the OnClose event of the main form if it has one or more MDI child
> forms open when the application is closed, but generates no error if all
of
> the child windows are closed prior to closing the application.

I had a similar problem which was caused by reference-by-interface to the
MDI children. The children were being freed via .Free and then by the
interface refernce going out of scope, thereby generating an AV. The
solution was to make sure that all interface references were set to nil
before anything closed.

Hope That Helps,
  Ignacio

Re:MDI Parent Form Activities between Close and Destroy


I'm not sure I understand what you mean by "reference-by-interface".

The MDI Children belong to a "plug-in" package I load via an IInterface
descendant.  Is that what you're referring to?

How do I set the interface references to Nil?

Gabe

Quote
"Ignacio Vazquez" <ivazquezATorioncommunications.com> wrote in message

news:3ebfcd7d@newsgroups.borland.com...
Quote
> "Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message
> news:3ebfc7af@newsgroups.borland.com...
> > What happens between an MDI form firing its OnClose and OnDestroy
events?
> I
> > ask, because I have a program that generates an Access Violation
> immediately
> > after the OnClose event of the main form if it has one or more MDI child
> > forms open when the application is closed, but generates no error if all
> of
> > the child windows are closed prior to closing the application.

> I had a similar problem which was caused by reference-by-interface to the
> MDI children. The children were being freed via .Free and then by the
> interface refernce going out of scope, thereby generating an AV. The
> solution was to make sure that all interface references were set to nil
> before anything closed.

> Hope That Helps,
>   Ignacio

Re:MDI Parent Form Activities between Close and Destroy


Where will I set this?  In the OnClose of the child form, or what?

Gabe

Quote
"Ignacio Vazquez" <ivazquezATorioncommunications.com> wrote in message

news:3ebfd17b$1@newsgroups.borland.com...
Quote
> "Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message
> news:3ebfceb9@newsgroups.borland.com...
> > I'm not sure I understand what you mean by "reference-by-interface".

> > The MDI Children belong to a "plug-in" package I load via an IInterface
> > descendant.  Is that what you're referring to?

> Bingo.

> > How do I set the interface references to Nil?

> MyInterfacedForm:=nil;

> By doing so, you assure that MyInterfacedForm.Free has no effect, whereas
> the interface is freed via MyInterfacedForm._Release when you set the
> reference to nil.

> Hope That Helps,
>   Ignacio

Re:MDI Parent Form Activities between Close and Destroy


Quote
"Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message

news:3ebfd25d$1@newsgroups.borland.com...

Quote
> Where will I set this?  In the OnClose of the child form, or what?

In the OnClose event of the parent form.

Cheers,
  Ignacio

Re:MDI Parent Form Activities between Close and Destroy


Quote
"Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message

news:3ebfceb9@newsgroups.borland.com...

Quote
> I'm not sure I understand what you mean by "reference-by-interface".

> The MDI Children belong to a "plug-in" package I load via an IInterface
> descendant.  Is that what you're referring to?

Bingo.

Quote
> How do I set the interface references to Nil?

MyInterfacedForm:=nil;

By doing so, you assure that MyInterfacedForm.Free has no effect, whereas
the interface is freed via MyInterfacedForm._Release when you set the
reference to nil.

Hope That Helps,
  Ignacio

Re:MDI Parent Form Activities between Close and Destroy


How do I cycle through the open children?

MDIChildren[index] := nil doesn't work, because you it's a read-only
property, as is ActiveMDIChild.

Gabe

Quote
"Ignacio Vazquez" <ivazquezATorioncommunications.com> wrote in message

news:3ebfd40d$1@newsgroups.borland.com...
Quote
> "Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message
> news:3ebfd25d$1@newsgroups.borland.com...
> > Where will I set this?  In the OnClose of the child form, or what?

> In the OnClose event of the parent form.

> Cheers,
>   Ignacio

Re:MDI Parent Form Activities between Close and Destroy


Quote
"Gabriel Covert" <wcovert@sygenex_dot_com> wrote in message

news:3ebfd839@newsgroups.borland.com...

Quote
> How do I cycle through the open children?

> MDIChildren[index] := nil doesn't work, because you it's a read-only
> property, as is ActiveMDIChild.

Hmm. I don't believe that that's the correct way to solve this.

I think that somewhere in your program you hold one or more references to
one or more interfaces. It's those specific references you have to nil out.
Just doing a carpet-bomb routine is likely to cause as many problems as it
solves.

Cheers,
  Ignacio

Other Threads