?
Solved

skip initialization section at design time

Posted on 2000-02-15
10
Medium Priority
?
1,178 Views
Last Modified: 2010-08-05
Hi experts,

I have some unit with "initialization-finalization" sections. The unit is implicity
imported into my components package. As result, "initialization" section is
running while Delphi is loading that components package.

I need to execute some procedures in "initialization" section only when
my application "realy" running. The code bellow may help you to understand why I need this.

//--------------------------------------------
unit SVC107;
interface
uses WINDOWS,SYSUTILS;

procedure RegisterIdle(aOwner : pointer; aIdle : TIdleProc);
procedure UnRegisterIdle(aOwner : pointer; aIdle : TIdleProc);

implementation
// ... skipped

initialization
   InitIdleSystem;
finalization
   DoneIdleSystem;
end.
//-----------------------

As you can see, it's "idle" mechanism can force some components and
other units to do a lot of unusefull things. (for example: scan database
for changes etc.)

I try to avoid of this by the way:
//-------------
  if Uppercase(copy(ExtractFileName(Application.ExeName),1,6))<>'DELPHI'
  then InitIdleSystem;
//-------------

But, it's seems to me, must be another way to detect "designtime".
Something like:
   if csDesigning in Application.ComponentState then ...
It doesn't work :)

Help wanted.

Igor.
0
Comment
Question by:ITugay
  • 5
  • 3
  • 2
10 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2521979
You can use a conditional define in your .DPK file (in the Option dialog) like this:

{$IFNDEF ASCOMPONENT}
initialization
   InitIdleSystem;
finalization
   DoneIdleSystem;
{$ENDIF}

This will then remove the code for the compiled component package, but when you compile your application it will be included.

Cheers,

Raymond.
0
 
LVL 9

Author Comment

by:ITugay
ID: 2526132
to rwilson;

this code extracted from my unit:

{$IFNDEF ASCOMPONENT}
initialization
     ShowMessage('Idle init');
     InitIdleSystem;
{$ENDIF}
finalization
      DoneIdleSystem;
end.                  


when Delphi started, I see message "Idle init".
something wrong?

best regards
Igor.

PS: i find out new method:

if Application.MainForm = nil
then ShowMessage('real mode')
else ShowMessage('design mode');
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2526149
Did you have ASCOMPONENT defined in the directories and conditionals for your package?

Cheers,

Raymond.
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 9

Author Comment

by:ITugay
ID: 2526181
to rwilson.

In which package? Lot of components from different packages used
this unit. Give me please more details. (If it possible).

Igor.
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 150 total points
ID: 2526342
Every package which compiles in this unit would need to define ASCOMPONENT.

I suspect this solution is moot however as you have found another method...

Cheers,

Raymond.
0
 
LVL 9

Author Comment

by:ITugay
ID: 2526379
to rwilson.

Ok, I get it and try it. The points will be yours after few days, if nobody tell me about variable or function that I need :).

Thanx Raymond, CU.

Igor.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2529189
? don't understand. Why does this 'csDesigning in ComponentState' doesn't work?

Zif.
0
 
LVL 9

Author Comment

by:ITugay
ID: 2530447
to Zif.

I don't know :)

You may try this

initialization
  if csDesigning in Application.ComponentState
  then ShowMessage('design')
  else ShowMessage('real');
end.

Everytime you will get message "real".

Igor.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2533234
Ah, correct, didn't knew this.

ok, i just found today a nice article

http://www.delphizine.com/features/1998/11/di199811YA_f/di199811YA_f.asp

Regards, Zif
0
 
LVL 9

Author Comment

by:ITugay
ID: 2534065
To ZifNab.

Sorry, but you have some missunderstanding of the task. I do not need to detect "Is Delphi or debugger now running". I need only know "who is calling initialization section: Delhpi  or my application".

By,
Igor.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
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…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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