mgesiot
asked on
Reciving PSafeArray nad OleVariant Data from COM ....
Hi Experts.
I'm building an OLE Automation Server that interfaces Excel XP :-(
Anyway.
I Recieve/Send one type of data that I don't know how to handle :
var Strings : PSafeArray
========================
PSafeArray is a pointer to a SafeArray.
In this case it points to an array of Strings
(The VB code is [strings() As Variant])
The array dimensions are [0..1, 0..x] where x is
the number of items sent.
In one case I need to read the array, in the second I need
to write it.
I DONT KNOW WHERE TO START FROM
Any help on how to read and write this structure will be appreciated.
Best Regards
Marco
I'm building an OLE Automation Server that interfaces Excel XP :-(
Anyway.
I Recieve/Send one type of data that I don't know how to handle :
var Strings : PSafeArray
========================
PSafeArray is a pointer to a SafeArray.
In this case it points to an array of Strings
(The VB code is [strings() As Variant])
The array dimensions are [0..1, 0..x] where x is
the number of items sent.
In one case I need to read the array, in the second I need
to write it.
I DONT KNOW WHERE TO START FROM
Any help on how to read and write this structure will be appreciated.
Best Regards
Marco
Btw. the other way around is like this:
function VariantToSafeArray(const Array: OleVariant): OleVariant;
begin
Assert(TVarData(Arr).VType =varArray) ;
Result:=PSafeArray(TVarDat a(Arr).VAr ray);
end;
And when it is in the Variant, you can just use it like a normal Pascal array...:
Edit1.Text:=Strings[0];
function VariantToSafeArray(const Array: OleVariant): OleVariant;
begin
Assert(TVarData(Arr).VType
Result:=PSafeArray(TVarDat
end;
And when it is in the Variant, you can just use it like a normal Pascal array...:
Edit1.Text:=Strings[0];
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Anyway I made it myself using
SAFEARREAYCREATE
SAFEARRAYGETDIM
SAFEARRAYGETUBOUND
SAFEARRAYPUTELEMENT
SAFEARRAYGETELEMENT
Api functions.
Now I wonder if I actually need all of this
or if the compiler takes charge of creating and
destroying the SafeArray.
I'll try your suggestions and let you know
within a couple of days.
Thanks again
Marco
Anyway I made it myself using
SAFEARREAYCREATE
SAFEARRAYGETDIM
SAFEARRAYGETUBOUND
SAFEARRAYPUTELEMENT
SAFEARRAYGETELEMENT
Api functions.
Now I wonder if I actually need all of this
or if the compiler takes charge of creating and
destroying the SafeArray.
I'll try your suggestions and let you know
within a couple of days.
Thanks again
Marco
ASKER
Thanks a lot
function SafeArrayToVariant(SaveArr
begin
TVarData(Result).VType:=va
TVarData(Result).VArray:=P
end;
[...]
var
Strings: OleVariant;
Temp: PSafeArray;
[...]
{I assume that Temp holds the PSafeArray)
Strings:=SafeArrayToVarian