Solved

Run routine after application start. (D7)

Posted on 2011-09-27
7
472 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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