Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread External module.
Sun, Aug 4 2013 6:31 AMPermanent Link

Abdulaziz Al-Jasser

Hi,

I am trying to create an external module.  Therefore I used the template that comes with EDB.  But I am not sure how to call the function and return the value from it inside the stored procedure.  Any tips on how to do it inside the module and how to call it from a stored procedure and get the return value?  This is what I got from EDB templates:

unit unit1;

interface

uses SysUtils, Classes, DB, edbextmodule;

type
 TEDBExternalModule1 = class(TEDBExternalModule)
   procedure EDBExternalModuleRoutine(const RoutineName: String);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 EDBExternalModule1: TEDBExternalModule1;

implementation

{$R *.dfm}


//This is my function. I am trying to call it with a pararmeter and return the value from it.
Function GetDiskSerialNumber(iLengthToReturn : Integer = 0) : String;
begin
        Result := 123456789;
end;

procedure TEDBExternalModule1.EDBExternalModuleRoutine(const RoutineName: String);
begin

  { Fill in the routine (function or procedure) execution code here.
    You can have multiple functions and/or procedures in a module.
    Use the RoutineName parameter to determine which function or
    procedure is being executed.  Use the public Params property of
    this external module (TParams object) to access the parameters to
    the function or procedure.  Do not modify the Params property other
    than to get/set the parameter values or Null flag.  Adding, removing,
    or changing the data type or parameter type of a parameter can cause
    serious problems. }
end;
Regards,
Abdulaziz Jasser
Sun, Aug 4 2013 7:17 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


Have a look in the extensions newsgroup. There's a post from me entitled

Work Generator / Text Filter /  External functions - latest versions

in there you'll find nlhFunctions.dpr which should show you how to do it.

Roy Lambert [Team Elevate]
Mon, Aug 5 2013 8:11 AMPermanent Link

Abdulaziz Al-Jasser

Thanks Roy, but even after reading your post I am still confused Frown I just cannot figure out:

1- Where is the call to the function/procedure inside the external module?
2- How to call a specific function/procedure inside the external module from the stored procedure?


I am still stuck with my code below which is very simple call to a function with one parameter and one return value from the function.  Can you give me some guide lines/tips/hints/code?  Thanks.



type
 TEDBExternalModule1 = class(TEDBExternalModule)
   procedure EDBExternalModuleRoutine(const RoutineName: String);
   procedure EDBExternalModuleCreate(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 EDBExternalModule1: TEDBExternalModule1;

implementation

{$R *.dfm}


//This is my function.
Function GetDiskSerialNumber(iLengthToReturn : Integer) : String;
begin
        Result := '1234567';
end;

procedure TEDBExternalModule1.EDBExternalModuleCreate(Sender: TObject);
begin
         DoRoutine('GetDiskSerialNumber');
end;

procedure TEDBExternalModule1.EDBExternalModuleRoutine(const RoutineName: string);
begin
         if UpperCase(RoutineName) = UpperCase('GetDiskSerialNumber') then
            Params.FindParam('Result').AsString := GetDiskSerialNumber(Params.FindParam('iLengthToReturn').AsInteger);
end;
Regards,
Abdulaziz Jasser
Mon, Aug 5 2013 8:39 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


Look at procedure TEDBExternalModule.DoRoutine(const RoutineName: TEDBString); in nlhFunctions

Roy Lambert [Team Elevate]
Mon, Aug 5 2013 3:33 PMPermanent Link

Abdulaziz Al-Jasser

Roy,

Got it right...thanks.

Regards,
Abdulaziz Jasser
Mon, Aug 5 2013 4:50 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Abdulaziz,

<< Thanks Roy, but even after reading your post I am still confused Frown I
just cannot figure out: >>

Get rid of the DoRoutine call and you're all set.

<< 1- Where is the call to the function/procedure inside the external
module? >>

That occurs in the SQL from the calling application.  You create the linkage
between the two by using:

CREATE MODULE...

followed by

CREATE FUNCTION/PROCEDURE....EXTERNAL NAME...

<< 2- How to call a specific function/procedure inside the external module
from the stored procedure? >>

After doing the above, just call the function like a native function or use
CALL for procedures from within SQL, or use a TEDBStoredProc component to
call it from code.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com

Mon, Aug 5 2013 5:17 PMPermanent Link

Abdulaziz Al-Jasser

Tim,

<<If you have any other questions, please let me know.>>

Thanks I've already got it working...amazing feature.  Now I am thinking on how to use those external procedures to enhance the speed of my huge application over slow internet connections ( < 10M).  My first thought is to move some complicated data validations in some forms to external modules (stored procedures) to be executed locally on the server side.  Any more ideas or experience to share?  Thanks in advance.

Regards,
Abdulaziz Jasser
Tue, Aug 6 2013 12:29 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Abdulaziz,

<< Thanks I've already got it working...amazing feature.  Now I am thinking
on how to use those external procedures to enhance the speed of my huge
application over slow internet connections ( < 10M).  My first thought is to
move some complicated data validations in some forms to external modules
(stored procedures) to be executed locally on the server side. >>

That's a good idea.  The more code that is server-side, the more secure it
will be and the better the performance will be, especially for slow WAN
connections.

Tim Young
Elevate Software
www.elevatesoft.com
Image