Solved

VarArrays and Automation

Posted on 1997-04-05
7
812 Views
Last Modified: 2012-05-04
I have the following function declaration
(from the typelib) of an Automation server:

Declare Function DrawLine (ByVal startPoint As SAFEARRAY,
                              ByVal endPoint As SAFEARRAY) As USERDEFINED

This function is expecting two arrays, each containing
three doubles.

If I attempt to call this function from Delphi as shown here,
I get an OLESys error from the server (type mismatch):

p1, p2: variant;
x1, y1, z1, x2, y2, z2: double;
x1 := 2.0; y1 := 4.0; z1 := 6.0;
x2 := 3.0; y2 := 5.0; z2 := 7.0;

p1 := VarArrayOf([x1, y1, z1]);
p2 := VarArrayOf([x2, y2, z2]);

MyAutoObject.DrawLine(p1, p2);

Does anyone know what the problem is here?

Please reply via email of possible.
0
Comment
Question by:Tony.Tanzillo
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:sperling
ID: 1335187
VarArrayOf returns an array and its size.

The function expects an array without a size.

type
  TSafeArray = ARRAY [1..3] OF DOUBLE

var
  p1, p2     : TSafeArray;



p1[1] := x1;
p1[2] := x2;

and so on.


Haven't tried, but it ought to do the trick.

Regards,

Erik.
0
 

Author Comment

by:Tony.Tanzillo
ID: 1335188
Eric - You haven't really answered the question entirely.

Please show how the TSafeArray variables p1 and p2 in your example get to the Automation Server via the call to the method that requires two variants.


0
 
LVL 3

Expert Comment

by:sperling
ID: 1335189
Have you tried

MyAutoObject.DrawLine(p1, p2);

with p1 and p2 declared as ARRAY [1..3] of Double

I don't know VB very much. Is SAFEARRAY predefined? If not, what is the definition? If I can assume that SAFEARRAY is declared as an array of 3 doubles, this should indeed work.


BTW! If my answer is wrong, reject it. If my answer needs clarification, leave a comment... Makes life much easier for us answering the questions... ;) And, you won't get remarks for rejecting too often.


Regards,

Erik.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Tony.Tanzillo
ID: 1335190
Your answer is wrong. All arguments to OLE Automation
methods must be of the type variant, you can't pass Delphi types to them.

The declaration shown is not Visual Basic, it's from the OLE type library of the server.

0
 
LVL 3

Expert Comment

by:sperling
ID: 1335191
I've never declared variants for anything but the OLE server object.... Done quite some automation against Word and Excel without problems. From Delphi I've passed PChars, integers, enumerated types and so on.

Declare Function DrawLine (ByVal startPoint As SAFEARRAY, ByVal endPoint As SAFEARRAY) As USERDEFINED

This is indeed Visual Basic syntax. Still, do you know the definition of SAFEARRAY? And, what automation server is this? Anything common like Office and so on, or some specialiced stuff?

And, did you actually *try* my code?



Regards,

Erik.

0
 

Accepted Solution

by:
Jon Shemitz earned 100 total points
ID: 1335192
I suspect what's going on is that VarArrayOf creates a safe array of Variant elements. Try using VarArrayCreate - it's lot less *convenient* than MyAutoObject.DrawLine(VarArrayOf([1, 2, 3], VarArrayOf([4, 5, 6]) - but it lets you create an array of varDouble's.
0
 

Author Comment

by:Tony.Tanzillo
ID: 1335193
The problem has been identified by Borland. The Automation Server is expecting a safearray of three OLE doubles. Under all circumstances, Delphi insists on using Variants.

VarArrayCreate demonstrates the exact same problem, and at this point, I should withdraw the question because the problem is inherint to Delphi's implementation of Automation.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now