Solved

Runtime packages

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 193
Convert a string into a TDateTime 5 73
Performance of SQL statement 37 137
Can Live bindings change TGrid Cell Colour ? 1 35
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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