Solved

skip initialization section at design time

Posted on 2000-02-15
10
1,131 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 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