Order of unit initialization. Any clues?
Posted on 2001-07-25
Well, I have a rather big project, with several (read lots of) units using each other.
Everything was fine until I tried to switch to RT libs.
Scaled down description:
Unit A contains some base classes, and some _global_ initialization code required by them. The code resides in the initialization section.
Unit B contains some class derivated from those in Unit A and in the initialization section makes use of the global data inited in Unit A. Since Unit A is listed in the uses clause of Unit B, this should be no problem (or would it?)
Anyway, the whole scheme was OK until I tried to switch the project to RT libraries. After I did that (build all, the whole treat), Unit B weirdly gets to be inited _before_ Unit A and this produces an error since the global init didn't happen yet at that time.
If I touch then Unit B (e.g. enter one benign space in the source) and run the project again, it performs well. However, when switching back to embedded libs (again with build all) it fails in the same way until I touch again Unit B.
By switching to RTlibs I mean nothing more than checking the appropriate box in Project's Options/Packages tab and then "Build all" from Project menu.
It's a C/S D3.
Did anyone encounter any similar behavior? Any suggestions? Any workarounds? (Pls, don't tell me to upgrade :) )