Solved

pointers, OLEVariant, Arrays of OLEVariant

Posted on 2001-09-13
4
1,434 Views
Last Modified: 2011-10-03
Can anybody point me to any documents which clearly explains how to use pointers with OLEVariant and Arrays of OLEVariant. I am being passed parameters of these types from a Server and need to extract the data that is being passed to my program. I am finding it all very confusing.

Thanks.
0
Comment
Question by:JohnMcGill
4 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6479481
Hi JohnMcGill,

you can use typecasting to convert pointer to integer and back.

var
  V: OLEVariant;
  T: TEdit;

begin
  V := Integer(Edit1);

  TEdit(Integer(V)).Text := 'some text';
end;

----
Igor.
0
 
LVL 14

Assisted Solution

by:AvonWyss
AvonWyss earned 100 total points
ID: 6479560
Arrays passed along in OLE automation are often pointers to so-called safe arrays (PSafeArray). These are arrays of OLE-compatible variants (OLEVariant). If you get a pointer to a safe array, you can quickly convert it to a OLEVariant array and vice-versa:

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

The other way around goes like this:

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

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

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

   Edit1.Text:=Strings[0];  

Hope this helps!
0
 
LVL 17

Expert Comment

by:geobul
ID: 9307969
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

split points between ITugay and AvonWyss

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

10 Experts available now in Live!

Get 1:1 Help Now