Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 23 total
Thread Returning a value from a stored procedure in an external module.
Sat, Jul 19 2014 8:08 AMPermanent Link

Abdulaziz Al-Jasser

Hi,

As we all know starting 2.16 the standard TParam in the light external module was changed to TEDBParamValues.  I was able to make the right changes but have an issue with the return value!!!  The stored procedures (Functions) do not longer return values!!!  Below is my code to pass paramterers and return values:

if UpperCase(RoutineName) = UpperCase('GetServerSerialNumber') then begin
  ParamValues.FindByName('Result').AsString := GetDiskSerialNumber_Win7(ParamValues.FindByName('iLengthToReturn').AsInteger);
end;

Did I miss something?
Regards,
Abdulaziz Jasser
Sat, Jul 19 2014 10:54 AMPermanent Link

Abdulaziz Al-Jasser

Better to say:

Can still return the value by using "Result" parameter as shown in previous post?

Regards,
Abdulaziz Jasser
Sun, Jul 20 2014 10:11 AMPermanent Link

Abdulaziz Al-Jasser

Maybe I should give some details.  The external nodule contains a small function that returns the hard disk manufacture serial no.  This function works fine if I use a separate simple project.  But within the external module I got null as a return value!!!  Below is the code.  Please try it in separate project and in an external module.

USES System.Win.ComObj,
          Winapi.ActiveX;


function GetWMIString(const WMIClass, WMIProperty: String): String;
const
        wbemFlagForwardOnly = $00000020;
var
        FSWbemLocator : OLEVariant;
        FWMIService   : OLEVariant;

        FWbemObjectSet: OLEVariant;
        FWbemObject   : OLEVariant;

        oEnum: IEnumvariant;
        iValue: LongWord;
begin;
        Result := '';

        FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
        FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');

        FWbemObjectSet:= FWMIService.ExecQuery(Format('Select %s from %s', [WMIProperty, WMIClass]), 'WQL',wbemFlagForwardOnly);
        oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;

        if oEnum.Next(1, FWbemObject, iValue) = 0 then begin
           if NOT VarIsNull(FWbemObject.Properties_.Item(WMIProperty).Value) then
              Result := FWbemObject.Properties_.Item(WMIProperty).Value;
        end;

        Result := Trim(Result);

        FSWbemLocator  := Unassigned;
        FWMIService    := Unassigned;
        FWbemObjectSet := Unassigned;
        FWbemObject    := Unassigned;
end;


Exmaple:

Showmessage( GetWMIString('Win32_PhysicalMedia', 'SerialNumber') );
Regards,
Abdulaziz Jasser
Sun, Jul 20 2014 10:16 AMPermanent Link

Abdulaziz Al-Jasser

I usually use a second procedure to avoid passing parameters to the stored procedure and to simplify things.  Example:


function GetDiskSerialNo : string;
begin
        Result := GetWMIString('Win32_PhysicalMedia', 'SerialNumber');
end;


So when I create a stored procedure/function I usually call "GetDiskSerialNo" directly with no parameters.

Regards,
Abdulaziz Jasser
Sun, Jul 20 2014 11:15 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz

I have a different environment to yours. I have W7x64 and use D2006 so 32 bit and 2.17b1 ANSI. One of my functions is


else if ckn = 'soundex' then begin
 if ParamValues.FindByName('sLength').Null
  then ParamValues.FindByName('Result').AsString := Soundex(ParamValues.FindByName('FldStr').AsString, 4)
 else ParamValues.FindByName('Result').AsString := Soundex(ParamValues.FindByName('FldStr').AsString, ParamValues.FindByName('sLength').AsInteger)


and that works perfectly.

There's, unfortunately, not a lot of point in my trying your code out in my environment. About all I can suggest is that you'll have to debug the dll in EDBManager.

Roy Lambert
Sun, Jul 20 2014 1:43 PMPermanent Link

Abdulaziz Al-Jasser

Roy mine is:

Win8.1 64bit + XE2 32bit + EDB 2.17b1

I was able to return value using the below code:

ParamValues.FindByName('Result').AsString := 'The return value';


But with the function it's not working!!!

Regards,
Abdulaziz Jasser
Sun, Jul 20 2014 3:56 PMPermanent Link

Abdulaziz Al-Jasser

It was working with EDB 2.11b3.  But after upgrading to 2.17b1 it returns null all the time!!!
Regards,
Abdulaziz Jasser
Mon, Jul 21 2014 4:47 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz

>I was able to return value using the below code:
>
>ParamValues.FindByName('Result').AsString := 'The return value';
>
>
>But with the function it's not working!!!

That says to me that its your function that is returning null. What happens if you change string to ansistring in it?

Roy Lambert
Mon, Jul 21 2014 9:09 AMPermanent Link

Abdulaziz Al-Jasser

Roy Lambert wrote:


<<That says to me that its your function that is returning null. What happens if you change string to ansistring in it?>>

First thought you are right.  But if test the function itself in a separate project then it works like a dream.  Moreover, it was working before inside the external module using 2.11b3

This is what's confusing me!!??

Regards,
Abdulaziz Jasser
Mon, Jul 21 2014 9:10 AMPermanent Link

Abdulaziz Al-Jasser

Roy Lambert wrote:

<<What happens if you change string to ansistring in it?>>

Still the same problem.

Regards,
Abdulaziz Jasser
Page 1 of 3Next Page »
Jump to Page:  1 2 3
Image