Board index » delphi » Closing main form during initialization

Closing main form during initialization

I am running D1.  I need to check on several database files etc.
during the initialization of my program.  I call this initialization
from my OnActivate event in my Main form.  If initialization fails, I
raise an exception and show dialog boxes etc.  and I need to terminate
the program.  

The problem I have is that I have an event in the main form for
OnResize.  The code for the OnResize event executes after the
OnActivate event code as a result I cannot get the application to
terminate with the Close command I have in my exception.  I set a
variable to indicate successful initialization.  How do I check this
variable immediately after all form initialization?  What event can I
use?  

My application consists of a tab set that drives a string grid.  I
want to pick one of these tabs as part of my application but not if my
initialization failed.  I sent the program through my OnClose event
which has an Application.Terminate statement in it.  Even then the
OnResize event code executes afterward.

I need the OnResize event to make sure that a couple of panels,the tab
set and a bit button stay on the bottom of the form when the user
lengthens the form.  I also want the form to have a uniform width at
all times and lengthen the string grid accordingly.

My kludgy workaround is to use a 'Start' button that the user must
click upon to begin using my app.

I'd appreciate any help.  Delete 'spam' in my e-mail address, thanks.

***Attention spammers!***
Use of this e-mail address for unsolicited messages implies
your acceptance of a $1000 fee charged to you. I do not want
nor respond favorably to 'spam'.

 

Re:Closing main form during initialization


Quote
Bill wrote:

> The problem I have is that I have an event in the main form for
> OnResize.  The code for the OnResize event executes after the
> OnActivate event code as a result I cannot get the application to
> terminate with the Close command I have in my exception.>

Windows requires that an application has at least one window visible
all the time. This is the so-called  mainwindow.  Calling Close in the
OnCreate event code doesn't work therefore. Instead , use
if SomeError then begin
  // show some error message;
  Application.Terminate;
end;

I think this might solve your problem

regards,
Dirk Claessens

Re:Closing main form during initialization


Quote
On Tue, 14 Oct 1997 20:30:15 GMT, bobr...@intrsoft.com (Bill ) wrote:
>The problem I have is that I have an event in the main form for
>OnResize.  The code for the OnResize event executes after the
>OnActivate event code as a result I cannot get the application to
>terminate with the Close command I have in my exception.  I set a
>variable to indicate successful initialization.  How do I check this
>variable immediately after all form initialization?  What event can I
>use?  

Maybe I'm missing something, but why not call the OnResize event
from the OnCreate or OnShow event - both of which preceed OnActivate?

procedure Form1.OnShow(Sender: TObject);
begin
  Form1.Resize(Self);
end;

JE McTaggart

Re:Closing main form during initialization


Have you tried moving your initialization out to the project unit.

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  SplashForm := TSplashForm.Create(Application);
  Splashform.Show;
  if form1.init then begin
    Splashform.Free;
    Application.CreateForm(TForm2, Form2);
    Application.Run;
  end else SplashForm.Free;
end.

The above was a simple MDI app, it showed the splashform while Init was
tested, but didnt show the main form until Application.Run or if Init
returned false.
The project unit is a much overlooked piece of code.

In article <3443ce8b.23222...@inet01.emsinfo.com>, Bill
<bobr...@intrsoft.com> writes

Quote
>I am running D1.  I need to check on several database files etc.
>during the initialization of my program.  I call this initialization
>from my OnActivate event in my Main form.  If initialization fails, I
>raise an exception and show dialog boxes etc.  and I need to terminate
>the program.  

Kind Regards
Claire, c...@HallworthHome.demon.co.uk

Re:Closing main form during initialization


Quote
On Tue, 14 Oct 1997 20:30:15 GMT, bobr...@intrsoft.com (Bill ) wrote:
>The problem I have is that I have an event in the main form for
>OnResize.  The code for the OnResize event executes after the
>OnActivate event code as a result I cannot get the application to
>terminate with the Close command I have in my exception.  I set a
>variable to indicate successful initialization.  How do I check this
>variable immediately after all form initialization?  What event can I
>use?  

I found out that the OnPaint event succeeds the OnResize event.  I
checked my variable for successful initialization in the OnPaint event
and close the form there, if I need to.  No kludgy start button is
needed. ( 3 weeks later I stumbled on my own answer.)

***Attention spammers!***
Use of this e-mail address for unsolicited messages implies
your acceptance of a $1000 fee charged to you. I do not want
nor respond favorably to 'spam'.

Other Threads