?
Solved

Run routine after application start. (D7)

Posted on 2011-09-27
7
Medium Priority
?
488 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 1000 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

770 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