tags:

views:

609

answers:

3

If a Modal form creates a form and does .Show, how can the parent later determine if the non-modal form is still open or if the user closed it?

+4  A: 

When you close a form, it calls Hide, which sets Visible to false. Try checking the Visible property.

Mason Wheeler
I had thought of that, but Delphi's help states: "If Visible is true, the form is visible unless it is completely obscured by other forms."So, .Visible might be false even though the form is still open, just covered...
Tom
Where does it say that? It is not true.
Lars Truijens
You're reading it wrong. If Visible is true, then the form is visible-to-the-user, unless it's covered by other forms, in which case Visible is still true but the user can't see it because it's covered. But if Visible is false, it's not going to display no matter what other forms are doing.
Mason Wheeler
And not all forms Hide when they are closed. That really depends on how the form is programmed.
Lars Truijens
Lars: I quoted the D7 help directly. Lars, when might a form NOT hide when closed?
Tom
Mason explained the Visible property well. Forms that decide to free themselfs when closed are really closed and not just hidden. It all depends on what you as a programmer decide is needed in each case.
Lars Truijens
Yeah, you can set it up to free a form when you close it. Bad idea to do this while you're holding a reference to it from somewhere else, for obvious reasons. My answer assumes it's your own form and you're sticking with the default behavior.
Mason Wheeler
+1  A: 

Let the child form notify the parent when it closes. The parent form could use the TForm.OnClose event of the child form to let itself inform when the child form closes.

Lars Truijens
A: 

All VCL components are tied into their parents with AddComponent and RemoveComponent notifications. If your form is set to Action = caFree in OnClose then it will free itself when the user (or you) closes it. This already notifies its parent and you can override the notification receipt in the parent to get this event. Bri

Brian Frost