Igor UL7AAjr
asked on
skip initialization section at design time
Hi experts,
I have some unit with "initialization-finalizati on" 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(ExtractFile Name(Appli cation.Exe Name),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.
I have some unit with "initialization-finalizati
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(ExtractFile
then InitIdleSystem;
//-------------
But, it's seems to me, must be another way to detect "designtime".
Something like:
if csDesigning in Application.ComponentState
It doesn't work :)
Help wanted.
Igor.
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');
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.
Cheers,
Raymond.
ASKER
to rwilson.
In which package? Lot of components from different packages used
this unit. Give me please more details. (If it possible).
Igor.
In which package? Lot of components from different packages used
this unit. Give me please more details. (If it possible).
Igor.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Zif.
ASKER
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.
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
ok, i just found today a nice article
http://www.delphizine.com/features/1998/11/di199811YA_f/di199811YA_f.asp
Regards, Zif
ASKER
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.
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.
{$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.