Link to home
Start Free TrialLog in
Avatar of crestty
crestty

asked on

load a packge at runtime; and show Form

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;
ASKER CERTIFIED SOLUTION
Avatar of stepashka
stepashka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of CleanupPing
CleanupPing

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.