Solved

Reciving PSafeArray nad OleVariant Data from COM ....

Posted on 2001-09-05
5
1,617 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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