Board index » delphi » PSafeArray and ASP question.

PSafeArray and ASP question.

Hi,

Im Wiriting a COM object (Active server object). I need to return an Array
of strings from COM object to Active server page.

This is the method of ActiveX Library implementation class:

function TPrueba.Get_Array: PSafeArray;
var
   Bounds: array [0..0] of SAFEARRAYBOUND;
   Data: WideString;
   i: Integer;
   V: OleVariant;
   Numeros: PSafeArray;
 begin
   Bounds[0].cElements := 3;                // The array has 3 elements
   Bounds[0].lLbound:= 0;                    // It's a zero-based array
   Numeros := SafeArrayCreate(VT_BSTR, 1, Bounds);// Create an array of
Strings
   V:= VarArrayCreate ([0,2], varOleStr ) ;
   for I:= 0 to 2 do                         // Fill the array
   begin
     V[i] := 'Cadena' + IntToStr (i);
     Data := V[i];
     SafeArrayPutElement(Numeros, i, Data);
   end;
   Result := Numeros;
   SafeArrayDestroy(Numeros);
end;

The asp code:

Dim ObjTest
Set ObjTest= Server.CreateObject("Pruebadll.PruebaClass")
if IsArray(ObjTest.Get_Array()) then
  Response.Write "Is Array"
  for each name in ObjTest.Get_Array
     Response.Write name  & "<BR>"
  next
else
  Response.Write "is not Array"
end if

?Can you advice me?

Some help will be gratefully apreciated.

 

Re:PSafeArray and ASP question.


Do this:

[HRESULT stdcall GetData ([out, retval] VARIANT* Result)]

function TFoo.GetData: OleVariant;
begin
  Result := VarArrayCreate ([0, 2], varVariant);
  Result [0] := 'Item 0';
  Result [1] := 'Item 1';
  Result [2] := 'Item 2';
end;

--
have fun
Binh Ly
http://www.techvanguards.com

Quote
"Julio Rivera" <jcriver...@hotmail.com> wrote in message

news:3b4b5cf5_1@dnews...
Quote
> Hi,

> Im Wiriting a COM object (Active server object). I need to return an
Array
> of strings from COM object to Active server page.

> This is the method of ActiveX Library implementation class:

> function TPrueba.Get_Array: PSafeArray;
> var
>    Bounds: array [0..0] of SAFEARRAYBOUND;
>    Data: WideString;
>    i: Integer;
>    V: OleVariant;
>    Numeros: PSafeArray;
>  begin
>    Bounds[0].cElements := 3;                // The array has 3 elements
>    Bounds[0].lLbound:= 0;                    // It's a zero-based array
>    Numeros := SafeArrayCreate(VT_BSTR, 1, Bounds);// Create an array of
> Strings
>    V:= VarArrayCreate ([0,2], varOleStr ) ;
>    for I:= 0 to 2 do                         // Fill the array
>    begin
>      V[i] := 'Cadena' + IntToStr (i);
>      Data := V[i];
>      SafeArrayPutElement(Numeros, i, Data);
>    end;
>    Result := Numeros;
>    SafeArrayDestroy(Numeros);
> end;

> The asp code:

> Dim ObjTest
> Set ObjTest= Server.CreateObject("Pruebadll.PruebaClass")
> if IsArray(ObjTest.Get_Array()) then
>   Response.Write "Is Array"
>   for each name in ObjTest.Get_Array
>      Response.Write name  & "<BR>"
>   next
> else
>   Response.Write "is not Array"
> end if

> ?Can you advice me?

> Some help will be gratefully apreciated.

Re:PSafeArray and ASP question.


Thanks Binh Ly.

Have a nice day!

Quote
"Binh Ly" <b...@castle.net> wrote in message news:3b4b805f$1_1@dnews...
> Do this:

> [HRESULT stdcall GetData ([out, retval] VARIANT* Result)]

> function TFoo.GetData: OleVariant;
> begin
>   Result := VarArrayCreate ([0, 2], varVariant);
>   Result [0] := 'Item 0';
>   Result [1] := 'Item 1';
>   Result [2] := 'Item 2';
> end;

> --
> have fun
> Binh Ly
> http://www.techvanguards.com

> "Julio Rivera" <jcriver...@hotmail.com> wrote in message
> news:3b4b5cf5_1@dnews...
> > Hi,

> > Im Wiriting a COM object (Active server object). I need to return an
> Array
> > of strings from COM object to Active server page.

> > This is the method of ActiveX Library implementation class:

> > function TPrueba.Get_Array: PSafeArray;
> > var
> >    Bounds: array [0..0] of SAFEARRAYBOUND;
> >    Data: WideString;
> >    i: Integer;
> >    V: OleVariant;
> >    Numeros: PSafeArray;
> >  begin
> >    Bounds[0].cElements := 3;                // The array has 3 elements
> >    Bounds[0].lLbound:= 0;                    // It's a zero-based array
> >    Numeros := SafeArrayCreate(VT_BSTR, 1, Bounds);// Create an array of
> > Strings
> >    V:= VarArrayCreate ([0,2], varOleStr ) ;
> >    for I:= 0 to 2 do                         // Fill the array
> >    begin
> >      V[i] := 'Cadena' + IntToStr (i);
> >      Data := V[i];
> >      SafeArrayPutElement(Numeros, i, Data);
> >    end;
> >    Result := Numeros;
> >    SafeArrayDestroy(Numeros);
> > end;

> > The asp code:

> > Dim ObjTest
> > Set ObjTest= Server.CreateObject("Pruebadll.PruebaClass")
> > if IsArray(ObjTest.Get_Array()) then
> >   Response.Write "Is Array"
> >   for each name in ObjTest.Get_Array
> >      Response.Write name  & "<BR>"
> >   next
> > else
> >   Response.Write "is not Array"
> > end if

> > ?Can you advice me?

> > Some help will be gratefully apreciated.

Other Threads