Solved

Run routine after application start. (D7)

Posted on 2011-09-27
7
465 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now