views:

294

answers:

2

Hi all,

I am going through most of my applications and porting them to D2009 and I have one application that makes use of dynamic packages. For the life of me I cannot get my host application to recognize classes registered in a package. I traced through and the initialization section in the package being loaded was called and RegisterClasses was called but when I do a GetClass() call the classes are not available. Is there someone out there who can enlighten me as to what might be going on? I have researched and looked to see if there are any issues with the D2009 release and dynamic packages and so far I have found nothing. I'm beginning to wonder if I have a corrupted installation of Delphi or some other problem.

TIA

+2  A: 

If you are using a 3rd party memory manager then make sure it is proven to work with D2009 (actually 2007 and up).

With FastMM (which is the default MM since 2007) you would have to set the UseRuntimePackages define in FastMM4Options.inc

Olaf Monien
A: 

Hello, make sure that the following steps are done:

  • Create a new package in Delphi;
  • Insert a form in this package;
  • Insert a "inicialization" section in the form and uses the RegisterClass method. (registerClass(TForm1)); Don't forget the "T".
  • Save and compile the package;
  • Close all;
  • Copy the .bpl file (c:\Users\Public\Documents\RAD Studio\5.0\Bpl) to the application folder;
  • Create a new aplication in Delphi;
  • Go in Project > Options > Packages, and check the box "Build with runtime packages";
  • Leave only "vcl;rtl" in the text field and click OK button;
  • Insert a button;
  • In the source of the button, insert the code:

procedure TForm1.Button1Click(Sender: TObject);

var

PackageModule: HModule; AClass: TPersistentClass;

begin

PackageModule := LoadPackage('Package1.bpl');

if PackageModule <> 0 then begin AClass := GetClass('TForm2');

if AClass <> nil then
  with TComponentClass(AClass).Create(Application)
    as TCustomForm do
  begin
    ShowModal;
    Free;
  end;

UnloadPackage(PackageModule);

end;

end;

  • Compile the application. =)
Musashi_RS