Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

skip initialization section at design time

Posted on 2000-02-15
10
Medium Priority
?
1,170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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