load a packge at runtime; and show Form

crestty
crestty used Ask the Experts™
on
here is my code for the on click event to load
the packed and show the Form.

I am unable to show the Form...

AClass = 0 when i Debug it ,, as if the
Class never  registers.


var
  PackageModule: HModule;
  AClass: TPersistentClass;
begin
  PackageModule := LoadPackage(ExtractFilePath(ParamStr(0))
    + 'AbtPack.bpl');
  if PackageModule <> 0 then
  begin
    AClass := GetClass('TFormAbout');
    if AClass <> nil then
      with TComponentClass(AClass).Create(Application)
        as TCustomForm do
      begin
        ShowModal;
        Free;
      end
     else
      ShowMessage('Class not registered');

    UnloadPackage(PackageModule);
  end
  else
    ShowMessage('Package not found');
end;




Here is my Package ini secetion / declaration

type
  TFormAbout = class(TForm)
    LabelVer: TLabel;
    Label2: TLabel;


.....

initialization
begin
  RegisterClass(TFormAbout);
end;

finalization
begin
  UnRegisterClass(TFormAbout);
end;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
1. Use FindClass instead GetClass. It calls GetClass and raise the exception if clas is not registered.

2. Check build with run-time packages checkbox and your application will be working

Commented:
add unit2 to your Application



nit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
uses unit2;

{$R *.DFM}

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;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterClass(TForm2);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterClass(TForm2);

end;

end.

best regards

Cesario
crestty:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial