[lazarus] Trying to port a Delphi graph
tony at maro.net
Sun Mar 30 22:21:31 EST 2003
Well, that's not quite working for me yet, but I've always been weak
with pointers, so I may just be confused. Here's the appropriate info I
think to make this decision:
TTrapezeInfo = record
Vals : Array[0..3] of T3DPoint; //real coords
Pixs : Array[0..3] of TPoint; //mapped positions
LineNo : LongInt;
DistanceToViewer : Double;
IsEdge : Boolean; //True for those forming the walls
AVG : T3DPoint; //average of real values
Color : TColor;
PTrapezeInfo = ^TTrapezeInfo;
Then, a TList called FTrapezes is created and items are added as:
T := New(PTrapezeInfo);
Then the dispose originally was "Dispose(FTrapezes[i])"
I've also tried "Dispose((FTrapezes[i] as PTrapezeInfo));" which results
in an invalid typecast. I also tried "Dispose((FTrapezes[i] as
TTrapezeInfo));" just for the heck of it and that fails with invalid
typecast as well.
Finally I did:
i : LongInt;
For i := 0 to FTrapezes.Count-1 do begin
P := FTrapezes[i];
FTrapezes[i] := nil;
And I THINK this is right... someone yell if not.
On Sun, 2003-03-30 at 15:54, Marc Weustink wrote:
> At 15:44 30-3-2003 -0600, Tony Maro wrote:
> >I'm trying to port a 3D graph unit I found for Delphi. I've already
> >done much of the conversion (messages and such) but ran into the
> >following routine:
> >Procedure TGraph3D.ClearTrapezes;
> >var i : LongInt;
> > For i := 0 to FTrapezes.Count-1 do begin
> > Dispose(FTrapezes[i]);
> > FTrapezes[i] := nil;
> > end;
> > FTrapezes.Pack;
> >FTrapezes is defined as:
> >FTrapezes : TList; //casts to PTrapezeInfo
> >But when it hits the "Dispose" line, I get:
> >"Use of NEW or DISPOSE is not possible for untyped pointers"
> >I'm not familiar with the DISPOSE keyword or function. Can someone help
> >me decipher what is supposed to be happening here?
> Dispose is the opposite of New.
> With New you can allocate dynamic variables like:
> P: PMyRecord
> if you don't need your variable anymore you should use Dispose to fee memory
> In this case Dispose(P);
> FPC in your case complains, since it doesn't know how to dispose a pointer.
> You can avoid that by casting FTrapezes[i] to the PointerType it contains
> To unsubscribe: mail lazarus-request at miraclec.com with
> "unsubscribe" as the Subject
> archives at http://www.lazarus.freepascal.org/mailarchives
Need a Linux replacement for Microsoft Money?
Check out CheckBook Tracker!
More information about the Lazarus