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

Re: Delphi 7 initialization section not call

315 views
Skip to first unread message

Peter Morris

unread,
Aug 9, 2004, 2:00:01 PM8/9/04
to
Hi

You could also register the classes in the

procedure Register;

of the package.


--
Pete
====
Audio compression components, DIB graphics controls, FastStrings
http://www.droopyeyes.com

Read or write articles on just about anything
http://www.HowToDoThings.com


Eric Lacroix

unread,
Aug 9, 2004, 2:12:02 PM8/9/04
to
Well this is not a bad idea but does the Register section will be called
even is my package is not a design time package ?


"Peter Morris" <pe...@removethis.droopyeyes.com> wrote in message
news:4117...@newsgroups.borland.com...

Eric Lacroix

unread,
Aug 9, 2004, 3:00:12 PM8/9/04
to
Thanks,

Thats mean even if the initialization and finalization function exist in the
BPL (View with dependency walker: @UnitName@initialization$qqrv) they may
not be executed by the delphi framework at all. I will have to call my self
or place elseware the functionnailty you describe.


"Rob Kennedy" <.> wrote in message news:4117c571$1...@newsgroups.borland.com...
> Eric Lacroix wrote:
> > I use the RegisterClass and the UnregisterClass procedure to register
> > external metaclass from other BPL or from the executable itself. When i
use
> > the RegisterClass procedure inside a initialization section of another
unit
> > and when this unit is not referenced into any other unit, the
initialization
> > section is not fired. This only append when the unit is linked into the
BPL
> > when i add this unit into the executable everything work find, same case
if
> > a add a reference to this unit.
>
> I came across the same problem a week ago.
>
> If your program is compiled using run-time packages, and your program
> uses at least one of the units in your package, then that package will
> be included in your program's list of required pacakges. (Choose the
> Information item from the Project menu to see that list.)
>
> The packages on that list are loaded automatically by Windows as it
> loads your EXE. Since Windows doesn't know about packages and
> initialization sections, it does not call the InitializePackage
> procedure. That procedure gets called automatically if you use the
> LoadPackage procedure. InitializePackage calls all a package's
> initialization sections.
>
> Any of the package's units that appear on your EXE's uses clauses will
> get initialized because the EXE start-up code will call them as it calls
> all the normal units' initialization sections.
>
> What you've discovered is that any "standalone" units in the package
> will not be initialized. They can't be initialized when the package
> first loads since the OS doesn't know that's necessary. They aren't
> initialized by the EXE since the EXE doesn't use those units. The
> package can't always initialize itself when it's loaded because of the
> vagaries of how Windows loads DLLs.
>
> What you need to do is initialize your package manually. I mentioned
> InitializePackage above. Call that in your DPR file. I have some code
> like this in my program to initialize a package called mcdb.bpl:
>
> var
> MCDB: THandle;
> begin
> MCDB := GetModuleHandle('MCDB.bpl');
> if MCDB <> 0 then InitializePackage(MCDB);
>
> Applciation.Initialize;
> Application.CreateForm(TMultiMain, MultiMain);
> Application.Run;
>
> if MCDB <> 0 then FinalizePackage(MCDB);
> end;
>
> InitializePackage only initializes the units that haven't already been
> initialized by the EXE's automatic start-up code. By checking the handle
> value for 0, I allow myself to turn off run-time packages --
> InitializePackage crashes when given a 0 handle, which is what
> GetModuleHandle returns when the package isn't loaded.
>
> I'm not as comfortable with the call to FinalizePackage, though. I
> haven't confirmed that all my package's unit's finalization sections
> really get executed at the proper times. I haven't looked into it,
> though, since my finalization sections aren't performing any critical
> operations -- just freeing memory that would get freed by the OS moments
> later anyway.
>
> Your other option is to load the package completely dynamically with
> LoadPackage and UnloadPackage. You won't be able to use any of the
> package's units in your program code.
>
> --
> Rob
>
> P.S. to Team B: Eric cross-posted his message to three newsgroups, none
> of which really seems appropriate, and I cross-posted my response. For
> future reference, what should I have done instead? Introduce yet another
> newsgroup and set follow-ups?


Peter Morris

unread,
Aug 9, 2004, 3:06:00 PM8/9/04
to
Strictly speaking your runtime package wont be installed into the IDE, so
you could add a design-time package which touches each unit by referencing a
class in someway.

Lars

unread,
Aug 9, 2004, 3:34:25 PM8/9/04
to

"Eric Lacroix" <elac...@cch.ca> skrev i en meddelelse
news:4117b8e2$1...@newsgroups.borland.com...
> Hi,
>
> I have create a Factory object similar to this one :

First why do you post in the BASM groupe ??

And second please read > http://info.borland.com/newsgroups/guide.html

>> Do not crosspost or multipost your message. Post your message to the
single most appropriate group. <<

Lars G


Atle Smelvær

unread,
Aug 9, 2004, 3:37:48 PM8/9/04
to
Why don't you use LoadPackage. I have no problem when using Load and
UnloadPackage...


Atle Smelvær

unread,
Aug 9, 2004, 3:44:59 PM8/9/04
to
Sorry for duplicated info, little fast there. Anyway. I use those procedures
wherever I use packages, and I've had no problem yet. Works like a charm.
And whenever you want to debug your package part, just include it inside the
uses clause instead. This is the best solution available for plugin
behaviour in a Delphi application (that is, if all plugins are made with
Delphi).

-A


Rob Kennedy

unread,
Aug 9, 2004, 4:03:05 PM8/9/04
to
"Atle Smelv�������������������������" wrote:
> Why don't you use LoadPackage. I have no problem when using Load and
> UnloadPackage...

If you do that, then your program cannot directly use any of the units
within that package. For some designs, that might be appropriate, but
for others, it's not.

--
Rob

Eric Lacroix

unread,
Aug 10, 2004, 7:47:54 AM8/10/04
to
Sorry

For the crossposting, but it seam that several group are non working, like
Borland.Public.Delphi.Ide even Borland.Public.Delphi.Language.ObjectPascal.
And because i dont know where to post my question i made it available into a
few group.

"Lars" <l...@adslhome.dk> wrote in message
news:4117d1bc$1...@newsgroups.borland.com...

Marc Rohloff [TeamB]

unread,
Aug 10, 2004, 7:56:03 AM8/10/04
to
On Tue, 10 Aug 2004 07:47:54 -0400, Eric Lacroix wrote:

> For the crossposting, but it seam that several group are non working, like
> Borland.Public.Delphi.Ide even Borland.Public.Delphi.Language.ObjectPascal.
> And because i dont know where to post my question i made it available into a
> few group.

Some groups have been closed and are now read-only. This doesn't mean
you can cross post. Please choose only one group or your messages will
be cancelled.


--
Marc Rohloff [TeamB]
marc rohloff at myrealbox dot com

0 new messages