Solved

pointers, OLEVariant, Arrays of OLEVariant

Posted on 2001-09-13
4
1,458 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
[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
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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: …

705 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