views:

276

answers:

1

Hi

I am using an COM in Delphi 7 that was created in C# and one of the methods of a class return an array of an type. However, when Delphi imports it, instead of an array of that type I get an PSafeArray.

How can I cast the items of that array into its base type?

I've tried to use SafeArrayGetElement but I couldn't find a way of casting the item into its original type.

A: 

I don't know exactly how Delphi handles the type library interpretation, but a SAFEARRAY has an associated type.

If you can view the type library for the C# assembly, you can probably glean the underlying type from there.

If not, you can call SafeArrayGetVarType on the array to get its associated type at run-time (this has had problems on SAFEARRAYs created by some APIs, though, so you may get garbage back.)

Most likely, though, it is exposed as a SAFEARRAY of VARIANT where every item is of a "dynamic" type.

Do you know if you can process VARIANTs in Delphi?

Kim Gräsman
Yes Delphi can handle Variants.The real issue is that I do know the type, but when I try to cast it into it an exception is thrown.I think all the problem is because the types are defined inside a COM.
Adilson Carvalho
I wonder if /casting/ is not the way to do it. Or is that the general mechanism for getting the value out of a Variant?
Kim Gräsman