Board index » delphi » Close form from OnShow or OnActivate event?

Close form from OnShow or OnActivate event?

D5: How can I close a form from its FormShow or FormActivate event?
WIthin the FormActivate event, I attempt to connect to a database.
If this is unsuccessful I want to close the form, but Close doesn't seem
to have any effect.
I've also tried bbCloseClick( Self ) to run the on click event of the
Close bit button. This does execute the code, but again ignores the Close
statement.
A workaround solution is to connect to the database before showing the
form (its modal by the way, in case this makes a difference) but I'd like
to know if there's a way to exit from the form.

I've also noticed that FormActivate seems to be called from within
FormActivate - is this correct, and if so, why?

Thanks for all suggestions.

 

Re:Close form from OnShow or OnActivate event?


Hi there. Try this:

procedure TForm1.FormActivate(Sender: TObject);
begin
   {process DB stuff here}
   if  not DB.Connected  then  Self.Release;
end;

Good luck!!

-DrDelphi
http://www.drdelphi.com

Quote
"David Carle" <davidca...@clara.net> wrote in message

news:3988EEFC.6565@clara.net...
Quote
> D5: How can I close a form from its FormShow or FormActivate event?
> WIthin the FormActivate event, I attempt to connect to a database.
> If this is unsuccessful I want to close the form, but Close doesn't seem
> to have any effect.
> I've also tried bbCloseClick( Self ) to run the on click event of the
> Close bit button. This does execute the code, but again ignores the Close
> statement.
> A workaround solution is to connect to the database before showing the
> form (its modal by the way, in case this makes a difference) but I'd like
> to know if there's a way to exit from the form.

> I've also noticed that FormActivate seems to be called from within
> FormActivate - is this correct, and if so, why?

> Thanks for all suggestions.

Re:Close form from OnShow or OnActivate event?


"David Carle" <davidca...@clara.net> skrev i en meddelelse
news:3988EEFC.6565@clara.net...

Quote
> D5: How can I close a form from its FormShow or FormActivate event?

Just do this:
  PostMessage(Self.Handle, WM_CLOSE, 0, 0);

But it would be a lot better not to call ShowModal if you don't want to show
the form!

Finn Tolderlund

Re:Close form from OnShow or OnActivate event?


Quote
David Carle <davidca...@clara.net> wrote:
>A workaround solution is to connect to the database before showing the
>form (its modal by the way, in case this makes a difference) but I'd like
>to know if there's a way to exit from the form.

Wild guess: Did you try putting "Abort" in the OnShow method?

Smola
--
Dash, Dash, Space
(use "ansmolci@" to reply)

Re:Close form from OnShow or OnActivate event?


Put a Timer on your form with a short delay.
have your onShow or onActivate enable the timer.
Place the following code in the Timer

Timer1.enabled := False;
close;

Mike
--
Mike Best Programming
Brisbane
Australia

Quote
David Carle <davidca...@clara.net> wrote in message

news:3988EEFC.6565@clara.net...
Quote
> D5: How can I close a form from its FormShow or FormActivate event?
> WIthin the FormActivate event, I attempt to connect to a database.
> If this is unsuccessful I want to close the form, but Close doesn't seem
> to have any effect.
> I've also tried bbCloseClick( Self ) to run the on click event of the
> Close bit button. This does execute the code, but again ignores the Close
> statement.
> A workaround solution is to connect to the database before showing the
> form (its modal by the way, in case this makes a difference) but I'd like
> to know if there's a way to exit from the form.

> I've also noticed that FormActivate seems to be called from within
> FormActivate - is this correct, and if so, why?

> Thanks for all suggestions.

Re:Close form from OnShow or OnActivate event?


I would also suggest this approach. It allows the Form to properly initialize
but closes it as though the user had clicked the close button.

Quote
Finn Tolderlund wrote:
> "David Carle" <davidca...@clara.net> skrev i en meddelelse
> news:3988EEFC.6565@clara.net...
> > D5: How can I close a form from its FormShow or FormActivate event?

> Just do this:
>   PostMessage(Self.Handle, WM_CLOSE, 0, 0);

> But it would be a lot better not to call ShowModal if you don't want to show
> the form!

> Finn Tolderlund

--
Cut down on Junk EMAIL
Remove NOSPAM to reply

Other Threads