What prompts the Forms and datamodules in a Delphi application is the code contained in the main program body (file .DPR). Delphi automatically places this code each time a new form or datamodule is added to the project, when it comes to a project to generate a .EXE.
When it comes to a project of package however, such code is not automatically included.
You will need to manually install 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 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 creating the instances in the initialization
of this Unit.
When a package is loaded, the existing code within the session initialization
of all the Units is executed in some order without control. When the package is downloaded, the existing code within the sessions finalization
of all the Units is executed, again without a guarantee of order.
I recommend reading a interesting article which may be of good 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, as all types declared within it are available for use as soon as the package be loaded.
Possibly when you load bpl, your datamodule is not loaded yet. if you do
dm_Connection := TdmDados.Create(Application);
– Caputo