Delphi - OleVariant a pointer in D6?

Delphi - OleVariant a pointer in D6?

DaSteelman
Contributor Contributor
1,113 Views
5 Replies
Message 1 of 6

Delphi - OleVariant a pointer in D6?

DaSteelman
Contributor
Contributor
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
0 Likes
1,114 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
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
0 Likes
Message 3 of 6

Anonymous
Not applicable
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]
0 Likes
Message 4 of 6

Anonymous
Not applicable
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! "James Belshan" schreef in bericht news:40d83c43$1_2@newsprd01... > 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 > > >
0 Likes
Message 5 of 6

Anonymous
Not applicable
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 "Jackrabbit" schreef in bericht news:12594185.1087916165524.JavaMail.jive@jiveforum1... > 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]
0 Likes
Message 6 of 6

Anonymous
Not applicable
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. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com AutoCAD based Security Planning Solutions: http://www.caddzone.com/securityplanning "Jack Houben" wrote in message news:17231714.1087886602297.JavaMail.jive@jiveforum2.autodesk.com... > 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
0 Likes