Changing properties of a component contained in a system module

Asked

Viewed 934 times

5

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

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

But I’m getting a message from Access Violation. I believe I’m not doing it the right way. How should I do it?

  • Possibly when you load bpl, your datamodule is not loaded yet. if you do dm_Connection := TdmDados.Create(Application);

1 answer

3


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.

  • Only one question, to pre-initialize an object is only Application.CreateForm(TDF001a, DF001a);, for example?

  • @Thiagothaison: the method Application.CreateForm is indicated for the creation of Forms, datamodules, frames and its descendants (but works with any component). To instantiate a class that is not one of these (an instance of TUsuario, for example) the constructor directly. Even to Forms could use the constructor directly. What the method in question does is instantiate and assign to the variable passed as the second parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.