Solved

Reciving PSafeArray nad OleVariant Data from COM ....

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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