Delphi XE2 Cannot get BPL plugin work

bpldelphidelphi-xe2moduleplugins

I tried to implement a simple module system with XE2 but couldn't get it to work. When I try to run it under IDE, I can get a handle from LoadPackage() but cannot get the class with GetClass() (even though it was RegisterClass()ed within initialization section of the BPL). When I try to run it under Windows, I get "This application has failed to start because rtl160.bpl was not found" error, and cannot even load the package.

Module code

type
  TfrModule = class(TFrame)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

procedure TfrModule.Button1Click(Sender: TObject);
begin
  ShowMessage('Hello');
end;

initialization
  RegisterClass(TfrModule);
  ShowMessage('Registered');

finalization
  UnregisterClass(TfrModule);
  ShowMessage('Unregistered');

Also, the initialization section is not being executed because I see no 'Registered' message box.

And the host app is something like this;

var
  hMod: HModule;
  fcMod: TPersistentClass;
  frMod: TFrame;

procedure TForm4.Button1Click(Sender: TObject);
begin
  hMod := LoadPackage('Module.bpl');
  if (hMod = 0) then Exit;

  fcMod := GetClass('TfrModule');
  if Assigned(fcMod) then
  begin
    frMod := TFrame(fcMod.Create);
    frMod.Parent := Panel1;
  end;
end;

Host app was linked with Runtime packages True. Module doesn't have a runtime packages option.

Another question. I saw this basic example all over the net but I plan to add more similar modules and what's going to happen if I try to RegisterClass() the second module's TfrModule class in its initialization? If I need to give different name for each module, there's no point of modules anyway. I mean, if the host must know exactly what the module's classes look like.

Best Answer

Everything works fine here. Host app uses only runtime packages vcl and rtl. The module requires also the rtl and vcl packages. These packages have also to be deployed. I see a 'Registered' message box and the GetClass function is also succesfully called ...

Related Topic