Re: Keeping invisible forms from showing at start-up




"Rob Kennedy" <me3@xxxxxxxxxxx> wrote in message
news:445n7jFgk3sU1@xxxxxxxxxxxxxxxxx
> Paul E. Schoen wrote:
> > The following code is part of my Delphi project file:
> >
> > Application.CreateForm(TfmOrt560, fmOrt560);
> > if ( (ParamCount = 0) or (ParamStr(1) = '!') ) then begin
> > fmOrt560.Show;
> > // Show splash screen until OnClick event hides form
> > While fmOrt560.Visible do begin
> > Sleep(100);
> > Application.ProcessMessages;
> > end;
> > end;
> > fmOrt560.Release;
>
> This will not free fmOrt560 until your program starts processing
> messages. Messages don't get processed until you call
> Application.ProcessMessages or Application.Run. Was that your intention?

Application.Run is called at the end of all the form creations. It's OK if
it is freed then, as it is set invisible in the loop.
>
> > Application.CreateForm(TfmOrtDebug, fmOrtDebug);
> > Application.CreateForm(TfmOrtComm, fmOrtComm);
> > Application.CreateForm(TfrmCalibration, frmCalibration);
> > Application.CreateForm(TForm1, Form1);
> > ... More forms
> >
> > I have set Form1 as my Main Form.
>
> Not according to the code above, you haven't. Your main form is fmOrt560
> because it is the first form in your program to finish being created via
> the Application.CreateForm method.

I set it to Main Form in the Project Options. If fmOrt560 was the main form,
wouldn't the application close when it closes? I explicitly call
Application.Terminate in Form1, after doing some clean-up.
>
> The CreateForm method has exactly two purposes:
>
> 1. Make sure Application.MainForm is assigned.

I thought this was done at initialization if explicitly set in Project
Options.

>
> 2. Ensure that the variable passed in as the second parameter is a valid
> reference to the form even while the form is still being created. This
> is a hack designed to encourage poor programming style through the use
> of global variables.

Unfortunately, I use a lot of global variables, due to my greater
familiarity with old style C programming and reluctance to use OOP except
where absolutely needed. I suppose it should be the other way around. It's
probably too late to change all that in this project.

>
> Is fmOrt560 a splash screen? I can't tell from the name.
>
Yes, but it only appears for the conditions specified in the Parameters


> > It seems like I have to create another form first to keep this from
> > happening.
> >
> > Maybe its a D4 glitch. I saw in Help that there was a change in creation
> > order from D3 to D4.
>
> The Delphi 5 help says this in the TApplication.CreateForm help: "By
> default the form created by the first call to CreateForm in a project
> becomes the application's main form."

D4 says about the same, but mentions overriding this default behavior by
setting Main Form in the Project Options. Your ideas will probably be
helpful if I restructure my program. I suppose I could autocreate Form1 in
the project as invisible, then use its OnCreate event to create the forms
needed, as well as the Splash Screen, if required.

One problem I am still working on is that the main Form1 does not show until
my initialization is complete, which takes several seconds, due to
intentional delays. I am using my procedure Delay(mSec), which uses a 100
mSec timer and processes messages while timing out, so that the
communications threads can continue in the background. I should probably
create a thread to do my initialization, and use WaitForEvent(mSec) in the
thread. Then I think my main form should appear immediately, and I can show
the progress of the initialization, rather than nothing (which becomes
disconcerting after about a second).

I tried putting the initialization in OnShow event handler of Form1, but it
seems that this event is triggered before the form actually appears. I don't
know exactly how to hook an event that says the form has actually appeared
on the screen. Maybe OnPaint?

I appreciate all your help, and eventually maybe I'll get used to OOP and do
things "correctly". It is helpful to get insight into the inner workings of
the operating system based on messages. My previous incarnation of this
project used a big idle loop that checked for keypresses or flags set by
other activities, and much of the processing was done in interrupt service
routines. The low level code I write for embedded processors still uses
similar means, so it is sometimes difficult to shift my way of thinking.

Paul


.



Relevant Pages

  • Re: AxHost and ActiveX initialization
    ... Thanks for the response, ... Here is my initialization code "copied" from similar code generated by VS: ... the lifetime of the form1? ... one ActiveX component onto form1 and run Form1? ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Difference between Form1() and Form1_Load() ?
    ... load of Form1. ... the constructor is executed before the all of the underlying Windows data has been initialized. ... you should wait until the Load event to do anything that involves actually interacting with Windows. ... But for any sort of internal data initialization, the constructor is a perfectly appropriate to do that. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH 1/2] srcu: RCU variant permitting read-side blocking
    ... "Paul E. McKenney" wrote: ... and drop 'for_each_cpu' initialization? ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: [patch] cpufreq: mark cpufreq_tsc() as core_initcall_sync
    ... On Fri, 17 Nov 2006, Paul E. McKenney wrote: ... When it is used before initialization, ...
    (Linux-Kernel)