Board index » delphi » Closing modal form in onshow

Closing modal form in onshow

Picture this...

Form called to be created and then showmodal method executed.

In the formshow method we have a call to a standard dialog (open file)

if the execute for the dialog is false we want to close the form and see it
no more.

Close method blows up.  Release method frees the resources but leaves the
program in a lockeed state, with the main form still in a modal lockout.

How??

John

 

Re:Closing modal form in onshow


Why don't you call the dialog.execute first, if the result is true then you
create and show your modal form, else do nothing?

Ping

Quote
John Tamburo <john...@mbfs.com> wrote in message news:395d0b8b@dnews...
> Picture this...

> Form called to be created and then showmodal method executed.

> In the formshow method we have a call to a standard dialog (open file)

> if the execute for the dialog is false we want to close the form and see
it
> no more.

> Close method blows up.  Release method frees the resources but leaves the
> program in a lockeed state, with the main form still in a modal lockout.

> How??

> John

Re:Closing modal form in onshow


Quote
John Tamburo wrote in message <395d0b8b@dnews>...
>Picture this...

>Form called to be created and then showmodal method executed.

>In the formshow method we have a call to a standard dialog (open file)

>if the execute for the dialog is false we want to close the form and see it
>no more.

>Close method blows up.  Release method frees the resources but leaves the
>program in a lockeed state, with the main form still in a modal lockout.

>How??

>John

If you don't mind that form flashing, you can use

PostMessage(Handle, WM_CLOSE, 0, 0);

in OnShow. Another solution is to create a method of your modal form, e.g.
function TYourForm.MyShowModal : integer;
and call it instead of ShowModal. In this method you can check what you need
to check (Execute open dialog, ...) and call (or not call)
result := ShowModal;

Igor

Re:Closing modal form in onshow


Gives us source to see the sequence of statements.

Thanks
Davie

Quote
John Tamburo wrote:
> Picture this...

> Form called to be created and then showmodal method executed.

> In the formshow method we have a call to a standard dialog (open file)

> if the execute for the dialog is false we want to close the form and see it
> no more.

> Close method blows up.  Release method frees the resources but leaves the
> program in a lockeed state, with the main form still in a modal lockout.

> How??

> John

Re:Closing modal form in onshow


I've had the same problem...
Here's some code that i've been using, cause somebody wanted to see it...

If i put the InputQuery before onshow is called, i have the variable on the
wrong form, i guess i could make global variables, but thats kinda messy...

procedure TForm2.FormShow(Sender: TObject);
begin
if not InputQuery('New Profile Name','Please Enter the name for your new
profile:', sProfileName) then  Form2.Free;
...
...
end;

Re:Closing modal form in onshow


Quote
Michael Lerch <i...@hotmail.com> wrote in message news:395ff24a@dnews...
> I've had the same problem...
> Here's some code that i've been using, cause somebody wanted to see it...

> If i put the InputQuery before onshow is called, i have the variable on
the
> wrong form, i guess i could make global variables, but thats kinda
messy...

> procedure TForm2.FormShow(Sender: TObject);
> begin
> if not InputQuery('New Profile Name','Please Enter the name for your new
> profile:', sProfileName) then  Form2.Free;
> ...
> ...
> end;

Do not free an object in its event.  Read the on-line help.  If it is a
TForm or its descendent, you can use the Release method.  But the form will
still show and then close, so the screen will flash.  Read the responses to
the thread.

Ping

Other Threads