🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.commandlinetools
Article #86

Dcc32 and unit initialization order problem

#86
From: Gerrit Beuze
Date: Wed, 30 Nov 2005 09:28
79 lines
2846 bytes
Hi all,

I have been using dcc32 for years to build final builds.
But currently I'm running into an odd problem:

When I build an executable (.dpr) with Delphi 7's dcc32.exe the resulting
executable has a different unit initialization / finalization order
than the same project build from within the IDE.

In fact: the version as build with dcc32 crashes because
the initialization section for a unit B that "uses" unit A is called
BEFORE the unit A initialization section. unit A obviously
does not "use" unit B, neither any other units that indirectly use unit B.

I noticed this in several places:
One begin very odd where unit A defines an ancestor class and unit B contains a descendant
Even here unit B is initialized BEFORE unit A.

In this case too: built with IDE initialization order is as expected, builr with dcc32 gives bad order.


And of course: the same problems occur in the finalization calling order.


The basic units layout is like this:

unit A;

interface

uses Classes etc;

type
  TServices = class (blablabla);

function GetServices: TServices;

implementation

function GetServices: TServices;
begin
  Result := _Services;
end;

var
  _Services: TServices;
initialization
  // Set up services: stored in global var in implementation section
end.

===================

unit B;
interface
uses unit A;
implementation
initialization
  GetServices.Something; // CRASH!!
end.


I made sure all compiler settings (D-, C- etc. are defined
identical in the project's config file that's used to build with dcc32.
All relevant units are in the same directory, so it's not a search path problem.



Questions:

#1 : Any idea what's causing this?

#2: Any workaround - = how to force module initialization orders ?

And no: I cannot provide a small reproducable case.

Thanks in advance,

Gerrit Beuze
ModelMaker Tools
Technical Details
Message-ID: <438d707c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: ff8f1,e459cf1f20edf27f,start
X-Google-Attributes: gidff8f1,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl>
Newsgroups: borland.public.delphi.commandlinetools
Subject: Dcc32 and unit initialization order problem
Date: Wed, 30 Nov 2005 10:28:03 +0100
Lines: 81
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 212.238.242.122
Message-ID: <438d707c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133342844 212.238.242.122 (30 Nov 2005 01:27:24 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail