Solved

Runtime packages

Posted on 1998-12-29
4
423 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:Gerhard100198
4 Comments
 
LVL 4

Expert Comment

by:dwwang
ID: 1353708
have you added MyFuncs in the uses list?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353709
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.


0
 
LVL 1

Expert Comment

by:bcrotaz
ID: 1353710
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?
0
 

Accepted Solution

by:
ptiemann2 earned 50 total points
ID: 1353711
The thing with packages is that they allow you to import object definitions whereas normal DLLs are made to import functions.
Do you really just want to import a function like TestFunc? No objects?
Then why do this package stuff at all? Just write a DLL, and use something like this:

  h := LoadLibrary();
  f := GetProcAddress ();
  f(123);
  FreeLibrary (h);

If you really need a package because you want to provide classes instead of functions, ok.. then this way as you wrote with LoadPackage.. but I never did that.

TIP: If your DLL uses the VCL (e.g. displays a form), then you MUST compile with packages, both the DLL and the EXEcutable. The reason is that they must use the same VCL instance or so.
See also my document about that at http://www.preview.org/q/q4047.shtml
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question