Solved

Run routine after application start. (D7)

Posted on 2011-09-27
7
478 Views
Last Modified: 2012-08-13
I'd like to start some routine after application start running. My application has main form but it is hidden. So, OnShow event can't be used.
Is there a way other than Timer and Application.OnIdle event?
Thanks.
0
Comment
Question by:3axap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Accepted Solution

by:
Mahdi78 earned 250 total points
ID: 36708736
Use DataModule or write you routine in program unit like the following example


program Project1;

uses
  Forms,
  Dialogs, // add Dialogs here to use showmessage procedure
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  showmessage('My routine here');
  Application.Run;
end.

Open in new window

0
 
LVL 25

Assisted Solution

by:epasquier
epasquier earned 250 total points
ID: 36708747
It would help to know what kind of routine you want to run. Is it related to your main form data ? what does it do ? why can't it be called in OnCreate event of your main form ?

why not calling it directly in you project source code ? This is a convenient place as you know for sure that all forms data have been initialized (the ones that are autocreated), but none of the GUI stuff and events occured (all managed in the main loop Application.Run)

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TfrmMain, frmMain);
  frmMain.BeforeRun; // Create this method of your main form and call it before Application.Run
  Application.Run;
end.

Open in new window

0
 

Author Comment

by:3axap
ID: 36708851
In OnCreate event of main form I'm starting thread that gives feedback before application finishes initializing.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:epasquier
ID: 36708877
ok, then try to start the threads just before Run
0
 

Author Closing Comment

by:3axap
ID: 36708906
Thank you.
0
 
LVL 9

Expert Comment

by:Mahdi78
ID: 36709069
As correction to my code, you should write your routine before CreateForm procedures


program Project1;

uses
  Forms,
  Dialogs, // add Dialogs here to use showmessage procedure
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  showmessage('My routine here');
  Application.CreateForm(TForm1, Form1);  // This should be the mainform
  Application.Run;
end.

Open in new window

0
 

Author Comment

by:3axap
ID: 36709140
Mahdi78, thanks for correction but I'd like to start my routine(thread) after main form creation and as late as possible.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 68
Delphi: making a BW image transparent 10 136
Tvertscrollbox like a whatsapp layout 5 68
Firemonkey Tcameracomponent resultion 1 44
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question