Board index » delphi » Repost: How 2 pass array of strings to VB from Delphi COM

Repost: How 2 pass array of strings to VB from Delphi COM

I'm implementing a interface in D6 COM server that a VB app will use. The
interface contains a method

function Thicknesses: OleVariant [propget, dispid $00000012, helpstring
'list of Thicknesses']; safecall;

The Calling VB code looks like this:

Private Sub FillCBThicknesses
    On Error GoTo except

    CBThicknesses.Clear

     Dim i As Long
     Dim thicknesses As Variant
     thicknesses = interfaceref..Thicknesses
     If Not IsNull(thicknesses) Then
       For i = LBound(thicknesses) To UBound(thicknesses)
            CBlThicknesses.AddItem (interfaceref.Thicknesses(i))
        Next
     End If
    Exit Sub
End Sub

I tried implementing Get_Thicknesses like this:

type
 TOleStrArray = array of PWideChar;
var
    p: Pointer;
begin
     Result := VarArrayCreate([0,1], varOleStr);
     p := VarArrayLock(Result);
     TOleStrArray(p)[0] := StringToOleStr(FloatToStr(0.6));
     TOleStrArray(p)[1] := StringToOleStr(FloatToStr(0.7));
     VarArrayUnlock(Result);
end;

When I run this though, the VB app throws an exception: "Could not convert
variant of type (Array OleStr) into type (OleStr)"

Any ideas?

--
Thanks

Scott Kellish
SoftSystem Solutions
skell...@comcast.net

--
Thanks

Scott Kellish
SoftSystem Solutions
skell...@comcast.net

 

Re:Repost: How 2 pass array of strings to VB from Delphi COM


I had a similar problem and I solved  by using
VarArrayCreate([0,iHighBound], varVariant).
All items to the array were then added as wideStrings.

Quote
"Scott Kellish" <skell...@siemens-hearing.com> wrote in message

news:3c83e9fd$1_1@dnews...
Quote
> I'm implementing a interface in D6 COM server that a VB app will use. The
> interface contains a method

> function Thicknesses: OleVariant [propget, dispid $00000012, helpstring
> 'list of Thicknesses']; safecall;

> The Calling VB code looks like this:

> Private Sub FillCBThicknesses
>     On Error GoTo except

>     CBThicknesses.Clear

>      Dim i As Long
>      Dim thicknesses As Variant
>      thicknesses = interfaceref..Thicknesses
>      If Not IsNull(thicknesses) Then
>        For i = LBound(thicknesses) To UBound(thicknesses)
>             CBlThicknesses.AddItem (interfaceref.Thicknesses(i))
>         Next
>      End If
>     Exit Sub
> End Sub

> I tried implementing Get_Thicknesses like this:

> type
>  TOleStrArray = array of PWideChar;
> var
>     p: Pointer;
> begin
>      Result := VarArrayCreate([0,1], varOleStr);
>      p := VarArrayLock(Result);
>      TOleStrArray(p)[0] := StringToOleStr(FloatToStr(0.6));
>      TOleStrArray(p)[1] := StringToOleStr(FloatToStr(0.7));
>      VarArrayUnlock(Result);
> end;

> When I run this though, the VB app throws an exception: "Could not convert
> variant of type (Array OleStr) into type (OleStr)"

> Any ideas?

> --
> Thanks

> Scott Kellish
> SoftSystem Solutions
> skell...@comcast.net

> --
> Thanks

> Scott Kellish
> SoftSystem Solutions
> skell...@comcast.net

Other Threads