Link to home
Start Free TrialLog in
Avatar of Gerhard100198
Gerhard100198

asked on

Runtime packages

I would like to create a unit file with a number of functions and procedures in this unit (let's call it MyFuncs.PAS).

I would also like to create a package containing this unit (MyFuncs.PAS) which I would like to distribute as a runtime package.

Further more, I would like to:
1) dynamically load this runtime package from my main project
2) use the functions & procedures contained within the units in this runtime package from my main project
3) I would like to be able to change properties of components in my main EXE from function/procedures contained within this runtime package.

I know how to create a new package (I just included MyFuncs.PAS in the pakage file and told it to compile a runtime only package (BPL-file)).

I then switched the options for my project to compile with runtime packages and added this new package (MyPackage.bpl) to the list of runtime packages.

I've places a button on the main form of my app. This is it's OnClick event:
-------------------------
var
  x: Integer;
begin
  x := LoadPackage('MyPackage.dpl');

  //TestFunc is a function in my MyPackage
  ShowMessage(TestFunc('one','two'));

  UnloadPackage(x);
end;

The problem is that every time I try and compile my project I get "undeclared identifier TestFunc".

What the heck am I doing wrong?
Avatar of dwwang
dwwang

have you added MyFuncs in the uses list?
Here is some of the help on runtime packages. You don't need to dynamically add it as you can simply add it to the project options. However, if you want to dynamically load it I think you will need to treat it more like a DLL and use GetProcAddress using the module handle loadPackage returns. Remember the package should register all components and classes that require registration.

Cheers,

Raymond.

A custom package is either a BPL you code and compile yourself, or a precompiled package from a third-party vendor. To use a custom runtime package with an application, choose Project|Options and add the name of the package to the Runtime Packages edit box on the Packages page. For example, suppose you have a statistical package called STATS.BPL. To use it in an application, the line you enter in the Runtime Packages edit box might look like this:

VCL40;VCLDB40;STATS

If you create your own packages, you can add them to the list as needed.


I have a similar problem, except I need to have forms as plug-ins.  ie they are not known at compile time, and are installed later, at run-time.  Forms don't get created properly in a DLL, in that you can't parent them onto a WinControl, so they look like a panel.  I wondered if packages are the answer.  If they are, then I'll need to dynamically load a package, about which I know nothing apart from the fact that it contains a descendant of TMyCustomForm.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of ptiemann2
ptiemann2

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