?
Solved

BPL + unit + procedure

Posted on 2003-02-27
4
Medium Priority
?
318 Views
Last Modified: 2010-04-04
Hi,

I cretae a .BPL.
At this BPL I add a simple unit (not TForm or TComponent) with many procedure and functions.

What's the way to use these procedure and functions when I dynamically load the package in my project ?

Jean-Luc !
0
Comment
Question by:Alphomega
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 300 total points
ID: 8033464
dynamically loaded packages don't differs from dll in this situation. you must define procedure/function type (prototype) and use GetProcAddress(..).
another way is to use interfaces - define one interface with all methods you need and implement it in your package as object.
when package is loaded get that interface by calling one proc/func (through GetProcAddress) and use it in your programm.
there of course is much more solutions (for examp. filling some pointer structures and etc.)

wbr, mo.
0
 

Author Comment

by:Alphomega
ID: 8035620
It doesn't work with GetProcAddress. Can you correct the code ?

unit fct_AlphoPackD6;

interface

function DivParDeux(V: integer): single; stdcall;

implementation

function DivParDeux(V: integer): single;
begin
 result := V / 2;
end;

end.

The unit is added to the package.

The code to call the function:

procedure TForm1.Button2Click(Sender: TObject);
type
  TMyProc = function(V: integer): single; stdcall;
var
  Plugin: HModule;
  MyProc: TMyProc;
begin
  Plugin := LoadPackage('AlphoPackD6.bpl');
  if Plugin <> 0 then
  begin
    @MyProc := GetProcAddress(Plugin, 'DivParDeux');
    if @MyProc <> nil then
    begin
     ShowMessage(FloatToStr(MyProc(25)));
     @MyProc := nil;
    end
    else
      ShowMessage('procedure not found in AlphoPackD6');
    UnloadPackage(Plugin);
  end
  else
    ShowMessage('AlphoPackD6 not found');
end;

I get
      ShowMessage('procedure not found in AlphoPackD6');
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8036539
as in dll you must export your functions.
at the end of your unit fct_AlphoPackD6 add exports block:

...
exports
  DivParDeux;
end.

mo.
0
 

Author Comment

by:Alphomega
ID: 8040008
Ok, it work very well !

Thanks a lot !
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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