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.
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!