views:

510

answers:

1

I have a unit wich defines TBla and the following code in the initialize section:

initialization
  RegisterClass(TBla);
  showMessage('registered');

This unit is inside a package. ok.

In a button click on my app I have the following code:

  LoadPackage('C:\temp\testes_packs\pack1\Package1.bpl');
  pc := GetClass('TBla');
  if pc = nil then
    ShowMessage('didnt work');

When I click the button the 'registered' message shows up. But, 'didnt work' shows too. Which indicates that the initialization wass called but the register class for some reason didn't work.

Ok, to prove that the LoadPackage was the problem, I included my unit (that contains TBla class) directly into my project and removed the loadPackage line and, tada the 'registered' message shows and the getClass works.

Any ideas?

+8  A: 

Your package needs to include "rtl" and "vcl" in its "requires" list. That way, the class-registration list will be the one in the shared package and not private to your own package.

Also, your application needs to be compiled to use run-time packages. In particular, the "rtl" and "vcl" packages need to be on its list of run-time packages.

Without doing both those things, the class-registration list used by one module will not be the same as the list used by the other module. They both have to use the same one, and the way to do that is to make sure that both modules are sharing the list exposed by the RTL.

Rob Kennedy
perfect. thanks.
Ricardo Acras