Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

No call of "initialization / finalization" in BPL?

517 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

Mario Werner

lukematon,
14.3.2005 klo 22.17.3814.3.2005
vastaanottaja

Hi there,

following a tutorial I swapped MDIChild forms in a BPL and load them dynamically into my program. This works quit fine so far.

But I discovered that it seems that there is no call of the initialization / finalization blocks in any unit of the BPL package. So this causes variables and objects to be initialized there are just dead which in turn causes problems in the further program flow.

To debug I set a breakpoint on a call in the initialization block which was marked as beeing OK and active but the program never stopped there. Then I put a "ShowMessage ('Hello?');" there which also not appeared.

Why is it like that and how can I correct this?! oO

Kind regards,
Mario

Rob Kennedy

lukematon,
15.3.2005 klo 1.56.3415.3.2005
vastaanottaja
Mario Werner wrote:
> But I discovered that it seems that there is no call of the
> initialization / finalization blocks in any unit of the BPL package.
> So this causes variables and objects to be initialized there are just
> dead which in turn causes problems in the further program flow.
>
> To debug I set a breakpoint on a call in the initialization block
> which was marked as beeing OK and active but the program never
> stopped there. Then I put a "ShowMessage ('Hello?');" there which
> also not appeared.

If the operating system loads the BPL as part of loading the associated
EXE, then not all the initialization sections will get called. Instead,
only the sections from the units that are explicitly used by something
else in the program get called.

If the code in the initialization section registers a class, and then
you only refer to that class indirectly, say by looking for it by name
in a list, then the unit's initialization section might not get called.
Adding that unit to any "uses" clause in your program should solve that
problem.

To work around this problem, you can initialize the package's units
yourself by calling the InitializePackage function, in the SysUtils
unit. It requires a module handle, which you can get by calling the
GetModuleHandle API function. That function will only call the
initialization sections of the units that haven't already been
initialized. That's my observation, anyway.

If you call InitializePackage, then you should also call
FinalizePackage. When your package gets unloaded, the finalization
sections will get called for all the units that were automatically
initialized.

If the OS does _not_ automatically load your package, then you are
loading it with the LoadPackage function. It initializes all the
package's units for you, so you don't need to call InitializePackage
yourself. Likewise, UnloadPackage will finalize everything for you.

--
Rob

Mario Werner

lukematon,
15.3.2005 klo 11.27.2215.3.2005
vastaanottaja

Hello Rob,

thanks alot! :) :) InitializePackage / FinalizePackage is the solution and now everything works as expected. :) *glad and happy*

Best wishes,
Mario

0 uutta viestiä