I'm trying to call a method in a COM DLL (written in C#) from a Delphi 2.0 client application. One of the parameters of the method I'm trying to call is a string array. Looking at the unit created by importing the library into a later version of Delphi, I see the string array parameter is defined as a PSafeArray.
This code works in Delphi 2007:
stringToEcho := VarArrayCreate([0, 0], varVariant);
stringToEcho[0] := 'Hello World!';
oResponse := iface.RequestResponse('EXTests', 'Echo', PSafeArray(VarArrayAsPSafeArray(stringToEcho)), 30, '', true);
This Delphi 2 code causes a "The parameter is incorrect" error at runtime when calling the RequestResponse method:
stringToEcho := VarArrayCreate([0, 0], varVariant);
stringToEcho[0] := 'Hello World!';
oResponse := iface.RequestResponse('EXTests', 'Echo', stringToEcho, 30, '', true);
Clearly a variant array is not a safearray and I need some way of converting or extracting the SafeArray from the variant array as I do in the Delphi 2007 example.
I have looked at the OLE2 unit & System units. I can see some Variant array support routines in System.pas but no variant array <-> SafeArray conversion routines.
How can I pass a PSafeArray to a COM automation server in Delphi 2?
Note that another point of difference is that I'm using early binding in Delphi 2007, and late binding in Delphi 2.
SafeArrayis not the same as avariant array. stackoverflow.com/a/2878492/62576 has some links that might help. You could also search this site for[delphi] safearrayfor some other posts that are relevant.