Solved

Runtime packages

Posted on 1998-12-29
4
421 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now