Delphi - OleVariant a pointer in D6?

Discussion in 'AutoCAD' started by Jack Houben, Jun 22, 2004.

  1. Jack Houben

    Jack Houben Guest

    Hello All,

    I create 2 spheres and then move the second until there is no more interference between the two. Keeping track of the new coordintes.
    following code works fine in Delphi 5:

    procedure TForm1.Button1Click(Sender: TObject);
    var
    AcadApp: AcadApplication;
    Drawing: AcadDocument;
    MSpace : AcadModelSpace;

    p1 : OleVariant;
    p2 : OleVariant;
    Sphere1 : Acad3DSOlid;
    Sphere2 : Acad3DSolid;
    Intersection : Acad3DSOlid;
    Interference : Boolean;
    begin
    AcadApp := GetAcadApplication(True);
    MSpace := AcadApp.ActiveDocument.ModelSpace;

    // Create point arrays
    p1 := VarArrayCreate([0,2], varDouble);
    p2 := VarArrayCreate([0,2], varDouble);

    // assign values to points
    p1[0] := 0.0; p1[1] := 0.0; p1[2] := 0.0;
    p2 := p1;

    // Create 3DSolid opbjects
    Sphere1 := MSpace.AddSphere(p1,5);
    Sphere2 := MSpace.AddSphere(p2,5);
    Interference:=True;

    // Move Sphere2 until there is no interference
    while Interference do
    begin
    Intersection:=Sphere1.CheckInterference(Sphere2,true);
    if Intersection=nil then
    Interference:=false
    else
    begin
    // Delete created intersection
    Intersection.Delete;
    // Intersection:=nil;
    p1:=p2;
    // Calculate new coordinates for Sphere2
    p2[0]:=p2[0]+0.1;
    p2[1]:=p2[1]+0.1;
    p2[2]:=p2[2]+0.1;
    // Move Sphere2
    Sphere2.Move(p1,p2);
    Sphere2.Update;
    p1:=p2;
    end;
    end;
    end;

    In Delphi 6 however, a change to p1 or p2 has the same effect on the other.

    Is D5 behaviour correct or is D6?

    Are there samples of AcadX use in Delphi? The links to samples in the "What's New" section on Tony's site seem to be broken...

    Thanks,
    Jack
     
    Jack Houben, Jun 22, 2004
    #1
  2. FWIW,
    If you're only interested in spheres, you can calculate the position where
    the two are just touching. For the direction you're moving the second
    sphere in, it would be:

    ' r1 and r2 are the two spheres' radii
    dx = (r1 + r2) / sqrt(3)
    dy = dx
    dz = dx

    p2[0] = p1[0] + dx
    p2[1] = p1[1] + dy
    p2[2] = p1[2] + dz

    If you try this and it doesn't give the right answer, let me know and I'll
    re-do my math.

    James
     
    James Belshan, Jun 22, 2004
    #2
  3. Jack Houben

    Jackrabbit Guest

    I compiled/ran this in D7. The values of P2 did not change after changing the values of P1.
    [pre]
    procedure TForm1.Button1Click(Sender: TObject);
    var
    P1: OleVariant;
    P2: OleVariant;
    Msg: string;
    begin
    P1 := VarArrayCreate([0,2], varDouble);
    P2 := VarArrayCreate([0,2], varDouble);

    P1[0] := 10.0;
    P1[1] := 10.0;
    P1[2] := 10.0;

    P2 := P1;

    Msg := IntToStr(P2[0]) + ', ' + IntToStr(P2[1]) + ', ' + IntToStr(P2[2]);
    MessageDlg(Msg, mtInformation, [mbOK], 0);

    P1[0] := 20.0;
    P1[1] := 20.0;
    P1[2] := 20.0;

    Msg := IntToStr(P2[0]) + ', ' + IntToStr(P2[1]) + ', ' + IntToStr(P2[2]);
    MessageDlg(Msg, mtInformation, [mbOK], 0);
    Application.Terminate;
    end;
    [/pre]
     
    Jackrabbit, Jun 22, 2004
    #3
  4. Jack Houben

    Jack Houben Guest

    Thanks James,

    I'm taking my first steps in ActiveX and AutoCad, your math is correct, but
    my spheres where just 2 solids that look nice!
    Delphi 5 seems to be ok and Jackrabbit points out Delphi7 is too. So I will
    have to get me D7...or work arround in D6

    Thanks for your reaction!
     
    Jack Houben, Jun 22, 2004
    #4
  5. Jack Houben

    Jack Houben Guest

    Hallo Jackrabbi,

    I dit the same in D5 and D6. D5 worked ok, for D6 I now have a workaround. I
    was just curious which one was correct.

    Last part of my message...
    Are there samples of AcadX use in Delphi? The links to samples in the
    "What's New" section on Tony's site seem to be broken..

    Have you any idea or samples?

    Thanks in advance!

    jack
     
    Jack Houben, Jun 22, 2004
    #5
  6. I don't see anything in your code that would suggest a problem.

    I do advise you to get rid of Delphi 6 and get Delphi 7. Delphi 6
    has problems with type library import.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 22, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.