Lazarus

Installation => General => Topic started by: dek on June 11, 2008, 10:32:34 pm

Title: Initial process that starts after open form
Post by: dek on June 11, 2008, 10:32:34 pm
I would like to start an initial process when the program starts.
The form does not appear until finish the process if I put it in TForm1.FormCreate procedure. Since it takes a time, I would like to open or show the form first.

How can I open the form first? Is there any procedure to execute after open the form?

Please advise.
Title: RE: Initial process that starts after open form
Post by: Leledumbo on June 12, 2008, 10:08:50 am
You can use either OnShow or OnActivate event. Declare a local typed constant so that the process isn't repeated everytime (i.e. only once).
Title: RE: Initial process that starts after open form
Post by: Bart on June 12, 2008, 10:23:37 pm
You can do something like:

declare the procedure like:
procedure DoIt(DummyParam: PtrInt);

then in OnActivate do
  Application.QueueAsyncCall(@DoIt, 0);

It will queue DoIt in the Apllication queue, so it will be executed after all items in the queue are handled. In effect this means that DoIt will be executed after the form has been drawn on the screen.

Bart
Title: RE: Initial process that starts after open form
Post by: dek on June 13, 2008, 07:42:46 pm
Thanks, Bart.

That is what I am looking for!
It works well for me.

Thanks again.
Title: Re: RE: Initial process that starts after open form
Post by: Phil on June 13, 2008, 08:10:21 pm
Quote from: "dek"
Thanks, Bart.

That is what I am looking for!
It works well for me.

Thanks again.


Here's what I use, which looks a bit cleaner:

  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  MainForm.Show;  {Display main form as backdrop}
  if MainForm.StartUpProgram then  {your routine here}
    Application.Run;

Thanks.

-Phil
TinyPortal © 2005-2018