0

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.

Brian Hawk
  • 728
  • 2
  • 12
  • 24
  • 2
    "This application has failed to start because rtl160.bpl was not found" is because the runtime packages are not properly installer on the machine. Are you running on a machine other than the dev machine? – David Heffernan Oct 08 '11 at 20:08
  • No David, both running on the same machine. The thing is, I also tried with Runtime packages False but same result. – Brian Hawk Oct 08 '11 at 21:34
  • 1
    Check that your path contains the folder that contains the RTL160.BPL and VCL160.BPL files. – Warren P Oct 08 '11 at 23:20

1 Answers1

0

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 ...

Erwin
  • 1,896
  • 1
  • 11
  • 17
  • I've compiled both module and host on Delphi 7, and was able to see the Registered message, which means initialization section gets executed but, GetClass() still returned nil. I was also able to set breakpoint within module code, which was not possible in XE2 (when I tried to set one, I got exceptions). I delved into the code's execution and found out that RegisterClass() being executed was totally different than the one in Classes unit. I really don't know what's going on. – Brian Hawk Oct 13 '11 at 22:44