?
Solved

pointers, OLEVariant, Arrays of OLEVariant

Posted on 2001-09-13
4
Medium Priority
?
1,478 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
3 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 400 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 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