Solved

Run routine after application start. (D7)

Posted on 2011-09-27
7
475 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
  • 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
Industry Leaders: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…

713 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