Error with ActiveX


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

All the examples given on  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);
 x, y : OleVariant;
 xCenter, yCenter : Double;
 TmpDraw, i : Integer;
  x := VarArrayCreate([0,36], varDouble);
  y := VarArrayCreate([0,36], varDouble);
  xCenter := StrToFloat(LabelX1.Caption);
  yCenter := StrToFloat(LabelY1.Caption);
  For i := 0 To 36 do
    x[i] := xCenter + 100 * Sin(pi/180*i * 10);
    y[i] := yCenter + 100 * Cos(pi/180*i * 10);
  TmpDraw := Map1.NewDrawing(dlSpatiallyReferencedList);

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 ?

Who is Participating?
BigRatConnect With a Mentor Commented:
A variant array is not an Automation type, only safearrays may be used.
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.
Also it might be better to pass everything through as a variant rather than a double, VB may prefer this.

VarArrayCreate([0,36], varVariant)
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

deflucAuthor Commented:
It's not a question of limit.

The problem appears also with 4 points as you can see here,1133,4880#msg-4880
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

  conArrayX, conArrayY: TObject;

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

  Map1.DrawPolygon( conArrayX, conArrayY, 37, clGreen, False);
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;
deflucAuthor Commented:
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.
deflucAuthor Commented:
Have you an example ?
deflucAuthor Commented:
BigRat says «only safearrays may be used. » but don't answers to my demand to provide an example.

The subject stays then unresolved.
All Courses

From novice to tech pro — start learning today.