[DUG] Closing a modal form from code in it

Jolyon Smith jsmith at deltics.co.nz
Sun May 8 12:27:53 NZST 2011


I'm pretty sure ModalResult is checked by, and is the exit condition for,
the message loop within the ShowModal function itself, so it is checked as
long as Windows messages are being handled by your process correctly.

 

If you call Close without setting ModalResult then the form will indeed
close but the message loop in ShowModal will never terminate and so that
function will never return.

 

Equally, setting ModalResult will cause the form to close without having to
call Close yourself, if showing modally.

 

Long and short - set ModalResult with an appropriate value that it not
mrNone to close a form that is being shown modally.

 

J

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Alistair Ward
Sent: Saturday, 7 May 2011 23:08
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Closing a modal form from code in it

 

Have you tried setting modalResult?

 

The usual way of closing a modal dialog is:

 

modalResult := mrOK;

 

somewhere in an event handler.

 

This is checked (from long ago memory) after most event handlers. The
exception (I think, from the same vague memories) is the FormShow event
itself.

 

Cheers,

Alistair.

On 7 May 2011 21:46, John Bird <johnkbird at paradise.net.nz> wrote:

I have a modal form that gets called to do some processing (involving Indy),
and when it has finished if all is OK I am trying to get the end code after
the Indy stuff to show status (which it does) and close the form (which it
doesn't).

 

The statement form2.close is being executed but is not closing the form.

What can stop a modal form being closed,  or any ideas what I need to do to
get it to close by itself when its finished?

 

(The form is opened by form2.ShowModal

and the code is in a procedure executed from the OnActivate event  - the
Show event also doesn't work)

 

John


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110508/c27663e7/attachment.html 


More information about the Delphi mailing list