?
Solved

Error with ActiveX

Posted on 2008-10-07
10
Medium Priority
?
509 Views
Last Modified: 2013-11-23
Hi

I'm using the MapWinGis ActiveX without problem behalve for the fonction DrawPolygon(xPoints, yPoints, numPoints, Color, fill).

All the examples given on http://www.mapwindow.org/  are in Visual Basic.

Dim myArrayX, myArrayY as Double
 
myArrayX(0) = 10
myArrayX(1) = 20
myArrayX(2) = 30
myArrayY(0) = 40
myArrayY(1) = 50
myArrayY(2) = 60
 
Dim conArrayX, conarrayY as Object
 
conArrayX = CObj(myArrayX)
conArrayY = CObj(myArrayY)
 
DrawPolygon(conArrayX, conArrayY, 3, myColor, True)
 
Translated in Delphi, then compilation is completed without error but execution fails at the delivery of the points parameters that must be «Arrays of double» for x and y.
Those parameters must be declared as  TOleVariant in the calling procedure.

My Code:
procedure TGisForm.Button5Click(Sender: TObject);
Var
 x, y : OleVariant;
 xCenter, yCenter : Double;
 TmpDraw, i : Integer;
begin
  x := VarArrayCreate([0,36], varDouble);
  y := VarArrayCreate([0,36], varDouble);
  xCenter := StrToFloat(LabelX1.Caption);
  yCenter := StrToFloat(LabelY1.Caption);
 
  For i := 0 To 36 do
  begin
    x[i] := xCenter + 100 * Sin(pi/180*i * 10);
    y[i] := yCenter + 100 * Cos(pi/180*i * 10);
  end;
 
  TmpDraw := Map1.NewDrawing(dlSpatiallyReferencedList);
  Map1.DrawPolygon(x,y,37,clGreen,False);
end;

genarates "An acces violation error at adress 1002C860 in the module MapWin~1.OCX".

if I remove the statements "VarArrayCreate", the error becomes "The variant is not an array".

Any idea ?


0
Comment
Question by:defluc
[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
  • 4
10 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22657993
Do the arrays you are passing in have the correct number of elements or is it unlimited?
The VB example above only showed 3 elements for each array where as you are using 37.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22658020
Also it might be better to pass everything through as a variant rather than a double, VB may prefer this.

VarArrayCreate([0,36], varVariant)
0
 

Author Comment

by:defluc
ID: 22658422
It's not a question of limit.

The problem appears also with 4 points as you can see here http://www.mapwindow.org/phorum/read.php?3,1133,4880#msg-4880
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22658531
Could you do what they did and convert the array to a TObject? Not sure why this would work but from that link that seems to be what they did

var
  conArrayX, conArrayY: TObject;

  conArrayX := TObject( x);
  conArrayY := TObject( y);

  Map1.DrawPolygon( conArrayX, conArrayY, 37, clGreen, False);
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22658544
I just noticed you also declared your arrays x and y as OLEVariant
Does it make any difference if you declared them as an array to start with and set their size instead of doing a create?

X, Y: array of double;
0
 

Author Comment

by:defluc
ID: 22659580
If I don't declare X and Y as OleVariant the compilation fails withe the message of non identical parameters Var original and formal.

DrawPolygon function requires OleVariant absolutely.
0
 
LVL 27

Accepted Solution

by:
BigRat earned 2000 total points
ID: 22668105
A variant array is not an Automation type, only safearrays may be used.
0
 

Author Comment

by:defluc
ID: 22670407
Have you an example ?
0
 

Author Comment

by:defluc
ID: 23243738
BigRat says «only safearrays may be used. » but don't answers to my demand to provide an example.

The subject stays then unresolved.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 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