Solved

Reciving PSafeArray nad OleVariant Data from COM ....

Posted on 2001-09-05
5
1,573 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:mgesiot
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6458507
Try this:

function SafeArrayToVariant(SaveArray: PSafeArray): OleVariant;
begin
     TVarData(Result).VType:=varArray;
     TVarData(Result).VArray:=PVarArray(SaveArray);
end;

[...]
var
     Strings: OleVariant;
     Temp: PSafeArray;
[...]
     {I assume that Temp holds the PSafeArray)
     Strings:=SafeArrayToVariant(Temp);
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6458517
Btw. the other way around is like this:

function VariantToSafeArray(const Array: OleVariant): OleVariant;
begin
    Assert(TVarData(Arr).VType=varArray);
    Result:=PSafeArray(TVarData(Arr).VArray);
end;

And when it is in the Variant, you can just use it like a normal Pascal array...:

    Edit1.Text:=Strings[0];
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 300 total points
ID: 6458520
Sorry, should be:

function VariantToSafeArray(const Arr: OleVariant): PSafeArray;
0
 

Author Comment

by:mgesiot
ID: 6459549
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
0
 

Author Comment

by:mgesiot
ID: 6478778
Thanks a lot
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question