Solved

skip initialization section at design time

Posted on 2000-02-15
10
1,112 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now