Link to home
Start Free TrialLog in
Avatar of Igor UL7AAjr
Igor UL7AAjrFlag for Kazakhstan

asked on

skip initialization section at design time

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.
Avatar of rwilson032697
rwilson032697

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.
Avatar of Igor UL7AAjr

ASKER

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');
Did you have ASCOMPONENT defined in the directories and conditionals for your package?

Cheers,

Raymond.
to rwilson.

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

Igor.
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

? don't understand. Why does this 'csDesigning in ComponentState' doesn't work?

Zif.
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.
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
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.