Board index » delphi » Trying to close Form in OnShow does not work - why

Trying to close Form in OnShow does not work - why

Hi

I am trying to close my Form in the OnClose event. My source looks something
like this..

procedure TMyForm.FormShow(Sender: TObject);
begin
         try
            ovReport.Execute;
         finally
            IF ovReport.Aborted THEN
               Close;
         end;
end;

I am running a report before the form appears... The result will be
displayed in the form. If somebody cancelled the report the form should not
appear.....

The de{*word*81} steps over the Close command but my application still shows the
form... What's wrong ????

Thanx

Marcus

 

Re:Trying to close Form in OnShow does not work - why


Close just doesn't work in OnShow.
Do this instead:
  PostMessage(Self.Handle, WM_CLOSE, 0, 0);

Marcus Holz <marc...@swiftech.net.sg> skrev i en
nyhedsmeddelelse:37abcd8...@news.swiftech.com.sg...

Quote
> I am trying to close my Form in the OnClose event. My source looks
something
> like this..

> procedure TMyForm.FormShow(Sender: TObject);
> begin
>          try
>             ovReport.Execute;
>          finally
>             IF ovReport.Aborted THEN
>                Close;
>          end;
> end;

> I am running a report before the form appears... The result will be
> displayed in the form. If somebody cancelled the report the form should
not
> appear.....

> The de{*word*81} steps over the Close command but my application still shows
the
> form... What's wrong ????

Re:Trying to close Form in OnShow does not work - why


Ouuups

I actually wanted to write "I am trying to close my Form in the OnShow
event" and not in the on Close event.......... A little typo..

Marcus

Quote
Marcus Holz <marc...@swiftech.net.sg> wrote in message

news:37abcd88.0@news.swiftech.com.sg...
Quote
> Hi

> I am trying to close my Form in the OnClose event. My source looks
something
> like this..

> procedure TMyForm.FormShow(Sender: TObject);
> begin
>          try
>             ovReport.Execute;
>          finally
>             IF ovReport.Aborted THEN
>                Close;
>          end;
> end;

> I am running a report before the form appears... The result will be
> displayed in the form. If somebody cancelled the report the form should
not
> appear.....

> The de{*word*81} steps over the Close command but my application still shows
the
> form... What's wrong ????

> Thanx

> Marcus

Re:Trying to close Form in OnShow does not work - why


YOU CAN'T DO THAT.

The ONClose is CALLED when the Form is Signaled to CLOSE.  You'll loop till
the stack overflows.

Call the OnFormXClose event, or code FORMx.CLOSE

Quote
Marcus Holz wrote in message <37abcd8...@news.swiftech.com.sg>...
>Hi

>I am trying to close my Form in the OnClose event. My source looks
something
>like this..

>procedure TMyForm.FormShow(Sender: TObject);
>begin
>         try
>            ovReport.Execute;
>         finally
>            IF ovReport.Aborted THEN
>               Close;
>         end;
>end;

>I am running a report before the form appears... The result will be
>displayed in the form. If somebody cancelled the report the form should not
>appear.....

>The de{*word*81} steps over the Close command but my application still shows
the
>form... What's wrong ????

>Thanx

>Marcus

Re:Trying to close Form in OnShow does not work - why


Quote
James King wrote:
> YOU CAN'T DO THAT.

   Um......  yes you can.

Quote

> The ONClose is CALLED when the Form is Signaled to CLOSE.  You'll loop till
> the stack overflows.

  Only if he writes it that way.

Quote

> Call the OnFormXClose event, or code FORMx.CLOSE

FormShow

  if Aborted then
     begin
       Width:=0;
       SendMessage(Handle,wm_Close);
     end;

  This should shrink your form to a 0 pixel width <invisible without being
invisible> and then post a close message to the form which will be processed in
it's own time and close the form.  <remember to reset the width when you want it
again.>

*******  above code tested and works in previous programs.  you might have to
play with the syntax.  *************

--
 Mark Zwicker
 Computer Programmer
 Adventus INC.
 m...@adventus.com

Other Threads