COM Array Parameters from MapBasic code to D5 dll

I have a D5 dll project with a function which needs to receive two arrays of
double from a MapBasic caller and use the x and y coords contained in those
two arrays to do some processing.  It works just fine, but as soon as the
function reaches its end; clause, an access violation occurs.

I suspect it's because the caller is passing arrays which are not COM
compatible datatypes.

Is there a way to receive an array of double from the MapBasic caller and
not receive an A/V?

the MapBasic code which passes  the array:

Dim Obj As Object
Dim X() as Float
Dim Y() as Float
Dim n as integer
Dim nPoints as Integer

 obj = CommandInfo(CMD_INFO_CUSTOM_OBJ)
 nPoints = ObjectInfo(obj,OBJ_INFO_NPNTS)
 ReDim X(nPoints)
 ReDim Y(nPoints)
 For n = 1 to nPoints
  X(n) = ObjectNodeX(obj,1,n)
  Y(n) = ObjectNodeY(obj,1,n)
 Next

 Call EditPoly(FrontWindow(), X(), Y(), nPoints)

The delphi code which processes the arrays:

function  EditPoly(MapID: integer; vpX: OleVariant; vpY: OleVariant;
nPoints: integer): Boolean;
var
  Obj: MBObject;
  n: integer;
  px, py : arrDouble;
begin
try
  px := vPx;
  py := vPy;
  Obj := MB.CreateBlankRegion(nil, nil);
  for n := 1 to nPoints do
    Obj.AddNode(1, n, pX[n - 1], pY[n - 1]);
  Result := EditObject(MapID,obj.VariableName,'');
except
  on e:exception do showMessage(e.message);
end;
end;