Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how delphi decide the execution order of initialization section ?

769 views
Skip to first unread message

stan

unread,
Jun 15, 2005, 2:15:25 AM6/15/05
to

how delphi decide the execution order of initialization section in all units used in project?

Thx.

krisztian pinter

unread,
Jun 15, 2005, 3:57:14 AM6/15/05
to

"stan" <st...@yahoo.com> wrote:
>how delphi decide the execution order of initialization section in all units used in project?

first, you should not depend on it. you must treat the execution
order random, with the following exceptions:

1. if a unit uses another unit, the used unit is initialized
first.

2. if two units both use each other, U1 uses U2 in interface,
U2 uses U1 in implementation, U1 initialized first.

if you need to control the order of the initialization in more
depth, you have to implement it some other way.

Guenther Wimpassinger

unread,
Jun 15, 2005, 6:22:33 AM6/15/05
to

"stan" <st...@yahoo.com> schrieb im Newsbeitrag

> how delphi decide the execution order of initialization section
> in all units used in project?

I do not know for sure, but AFAIK the compiler use the same sequence
as stated in the .dpr (your project file).

If the units, mentioned in the project's dpr file uses another unit with an
init-section, it is like krisztian described.

bye
Guenther


Guillem

unread,
Jun 15, 2005, 8:52:37 AM6/15/05
to
hi,

while you can you should *always* avoid having circular references, even in
the case Kristian says. They're sure ways to bugs and problems
--
Best regards :)

Guillem Vicens
Dep. informática Green Service SA
www.clubgreenoasis.com
--
In order to send me a mail, remove the -nospam


"krisztian pinter" <pint...@freemail.hu> escribió en el mensaje
news:42afdf5a$1...@newsgroups.borland.com...

Peter Below (TeamB)

unread,
Jun 15, 2005, 2:06:00 PM6/15/05
to
In article <42afc77d$1...@newsgroups.borland.com>, Stan wrote:
>
> how delphi decide the execution order of initialization section in all
> units used in project?

The execution path is not easy to determine manually. Basically the compiler starts
with the first unit in the projects DPR file, then proceeds with the first unit
in that units Interface Uses clause, then the first unit in that units interface
uses clause and so on, until it finds one that refers to no other units in the
interface. That is then compiled and added to the init list, then the next unit
in the previous units interface Uses clause is looked at (if there is any and
has not already been encountered before), and so on, recursively.
You can rely on any unit in the Interface Uses clause of unit A to be initialized
before unit A is initialized. There is no such guarantee for units named in the
Implementation Uses clause.

System is the first unit by default (even though it is not explicitely named in
the Uses clause, so the RTL initialization comes first.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


0 new messages