Solved

Reciving PSafeArray nad OleVariant Data from COM ....

Posted on 2001-09-05
5
1,513 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now