Solved

Runtime packages

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

16 Experts available now in Live!

Get 1:1 Help Now