Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi, VB COM and Arrays

2 views
Skip to first unread message

Rod Sherer

unread,
Apr 27, 2000, 3:00:00 AM4/27/00
to
I have written a VB COM object which calls other VB COM objects as a wrapper
for a Delphi front end. All my VB COM objects are registered with MTS and
have no trouble talking to each other or being called by vb applications.

However, the Delphi front end can not call any functions with arrays in them
(using SafeArrays on the Delphi side) as long as those VB COM objects are
registered with MTS. We set up a small test scenario which verified this.

What is causing this, and what can I do (aside from avoiding MTS) to solve
it.

RoustR

unread,
May 29, 2000, 3:00:00 AM5/29/00
to
I has tested your example. By the way, you dont write what a
kind array you used. Any way you can use simple variant type for
params.

I assume such situation

in VB sub look like this

Public Function test(arr() As Long) As Long
Dim i As Long
Dim r As Long

For i = LBound(arr) To UBound(arr)
r = r + arr(i)
Next
test = r
End Function

In Delphi I have imported TypeLib and got
const
CLASS_Class1: TGUID = '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';
type
_Class1 = interface(IDispatch)
['{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}']
function test(var arr: PSafeArray): Integer; safecall;
end;

now access for Com object

procedure TForm1.Button2Click(Sender: TObject);
var
p: _Class1;
a: variant;
i: integer;
begin
p := CreateComObject(CLASS_Class1) as _Class1;
a := VarArrayCreate([0,2],varInteger);
a[0] := 1;
a[1] := 10;
a[2] := 100;

i := p.Test( PSafeArray(TVarData(a).VArray) );
showmessage( IntToStr(i)) ;
end;

All work fine. It isn`t MTS itself, this is COM. There is
another way to use your COM object. I may create safearray via
API (SafeArrayCreate, SafeArrayPutElement, SafeArrayDestroy)
like any C programmer. But this is some difficult.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


0 new messages