Change properties of a component contained in a system module

5

I am modulating a system developed in Delphi XE3. One of my modules named Default has dmDados with a connection. In my main application, in onShow of my main Form I'm loading the module and trying to disconnect my connection component:

LoadPackage('modules/Default.bpl');
dm_Connection.ZConnection.Disconnect;

But I'm getting an Access Violation message. I believe I'm not doing it the right way. How should I do it?

    
asked by anonymous 04.05.2014 / 01:22

1 answer

3

What forms the forms and datamodules in a Delphi application is the code contained in the main program's body ( .dpr file ). Delphi automatically puts this code every time a new form or datamodule is added to the project when it comes to a .EXE .

When it comes to a package project however, such a code is not automatically included.

You will need to manually instantiate all the objects you want inside a package . This is especially true when the programmer decides to load the runtime package manually, as it seems that is what you are doing (calling LoadPackage ).

One way to pre-initialize a series of objects within the package is to choose a unit and add the code for the creation of the instances in initialization of this unit .

When a package is loaded, the existing code within the initialization session of all the units runs in some uncontrolled order. When the package is unloaded, the existing code within the finalization sessions of all the units runs, again without a guarantee of order.

I recommend reading an interesting article that might be of value to you. This article makes a comparison between the use of DLLs and packages and shows how the latter are easier and more straightforward, since all types declared inside it are available for use as soon as the package in> to be loaded.

    
04.05.2014 / 16:20