Home RAP

calling functions in dynamically loaded DLL from RAP/passthru functions

edited February 2003 in RAP
Hi,
I am fairly new to RAP so please bear with me :-).
I have worked through the examples in help file and have written a few
passthrough functions. Everything seems to work fine.
I need to call few functions from a dynamically loaded dll (using
loadlibrary) in my passthrough functions. Are there any caveats? Any gotacha
I need to be aware of? I have reproduced a snippet of code below.
I tried to register this fucntion in the end user explorer and it did
register without a hitch. However when i placed a label on the custmoer
report and tried to assign this function to onGetText of a label that I had
placed on the report , all i got was an error during the preview. After that
I can not preview this particular report - I get a corrupt blob field error
message. What did I do wrong?
Also how do I register this function so that it is available during design
time for all the reports ?
I am using Delphi 5 EE- update pack 2 and report builder enterprise 6.03.
Upgrading the version of Delphi as well as Report builder right now is not
an option.
Any help/insight gratefully acknowledged.
Paras

---begin code-------------------
CONST
DLL = 'test.dll'; -- for test dll coded in delphi, function declared as
register. Actual function in C, need to declare func_name as Stdcall latter.

.......
procedure TMyFunction.ExecuteFunction(aParams: TraParamList);
var
fhandle : Thandle;
fresult : string;
myFunc = Function :String;
CONST
FUNC_NAME = 'myfunction';
begin
inherited;
fhandle:= LoadLibrary(PCHAR(MY_DLL));
try
if flib > HINSTANCE_ERROR then
@myFunc := GetProcAddress(fhandle, Pchar(FUNC_NAME));
if assigned(@myFunc) then
fresult := myFunc
else
fresult := 'Failed';
SetParamValue(0,fresult);
finally // wrap up
if fhandle> 32 then FreeLibrary(fhandle`);
end; // try/finally
end;

Comments

  • edited February 2003
    Hi paras,

    How about loading the DLL once (initialization or delayed loading on first request)?
    I recommend to design all reports during runtime! (you still can register the RAP pass-through package into Delphi's IDE)


    --------------------------------------------------
    Article: Accessing Pass-Through Functions
    in Delphi Design-Time
    ---------------------------------------------------

    "How do I make my pass-through functions available
    at design-time?"

    Since pass-through functions are registered with RAP by
    calling raRegisterFunction (typically in the Initialization
    section of a unit), to make your functions available
    at design-time we simply need to arrange to have the
    initialization section of your unit executed at
    design-time.

    To do so, we'll create a design-time package and add in
    your units.

    Do the following:

    1. Select New... from the File menu in Delphi.
    2. In the New Items dialog, select Package and click OK.
    3. In the Package editor, click the Options button.
    4. In the Description tab:
    - Type in a meaningful Description, such as "My RAP
    Functions"
    - Set usage options to Designtime only.
    5. Click OK.
    6. Right-click the Contains node and select Add.
    7. In the Add dialog, enter the unit or units that
    contain the functions you wish to make available.
    8. Click OK.
    9. Save your package with a meaningful name and click
    the Install button.

    Your functions should now be available within RAP
    at Delphi design-time.


    once more, I don't recommend it.

    please more infos!


    vague error description, isn't it?
    I guess you have a database problem, what database are you using?
    I don't see any relation between your RAP function and the shown error.

    regards,
    Chris Ueberall;
  • edited February 2003
    Chris,
    Thanks for your reply.
    I will try to do as you suggested and will be back for more help :-).
    Regards
    Paras

    ---Message snipped-------------------
This discussion has been closed.