Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2003-03

Trying to port a Delphi graph

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Weustink
to Tony Maro: I'm trying to port a 3D graph unit I found for Delphi. I've already done much of the…
Tony Maro wrote 23 lines
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; begin For i := 0 to FTrapezes.Count-1 do begin Dispose(FTrapezes[i]); FTrapezes[i] := nil; end; FTrapezes.Pack; end; 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:

var
   P: PMyRecord
begin
   New(P);
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

Marc

Reply by email

Marco van de Voort
to Marc Weustink: Dispose is the opposite of New. With New you can allocate dynamic variables like: var P:…
Show quoted text 18 lines
> >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: var P: PMyRecord begin New(P); 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

Delphi accepts it, then so should FPC. I suspect it dates from the time of early Delphi compability where freemem always had to have a size parameter. It doesn't need that anymore nowadays, so that would be the same for dispose?

Reply by email

Tony Maro

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;
begin
  For i := 0 to FTrapezes.Count-1 do begin
    Dispose(FTrapezes[i]);
    FTrapezes[i] := nil;
  end;
  FTrapezes.Pack;
end;

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?

Thanks,

Tony Maro http://tony.maro.net/ Check out my software "CheckBook Tracker" A GPL (free) replacement for Microsoft Money!

Reply by email

Peter Vreman
to Marc Weustink: Dispose is the opposite of New. With New you can allocate dynamic variables like: var P:…
Show quoted text 28 lines
> > > >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: > > var > P: PMyRecord > begin > New(P); > > 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 Delphi accepts it, then so should FPC. I suspect it dates from the time of early Delphi compability where freemem always had to have a size parameter. It doesn't need that anymore nowadays, so that would be the same for dispose?

We've to add support for it. But i would say only in Delphi mode since it's bad coding. To free an untyped pointer you have to use Freemem(pointer).

Btw. Another difference between Dispose() and Freemem() is that the type that is passed to dispose() is also used to generate a call to Finalize()

Reply by email

Tony Maro
to Marc Weustink: Dispose is the opposite of New. With New you can allocate dynamic variables like: var P:…

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:

Type
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;
end;
PTrapezeInfo = ^TTrapezeInfo;
Then, a TList called FTrapezes is created and items are added as:
T := New(PTrapezeInfo);
fTrapezes.Add(T);

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:

Procedure TGraph3D.ClearTrapezes;
var
  i : LongInt;
  P: PTrapezeInfo;
begin
  For i := 0 to FTrapezes.Count-1 do begin
    P := FTrapezes[i];
    Dispose(P);
    FTrapezes[i] := nil;
  end;
  FTrapezes.Pack;
end;

And I THINK this is right... someone yell if not.

Marc Weustink wrote 47 lines
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; >begin > For i := 0 to FTrapezes.Count-1 do begin > Dispose(FTrapezes[i]); > FTrapezes[i] := nil; > end; > FTrapezes.Pack; >end; > >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: var P: PMyRecord begin New(P); 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 Marc _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
Thanks, Tony Maro Need a Linux replacement for Microsoft Money? Check out CheckBook Tracker! http://tony.maro.net/

Reply by email

Peter Vreman
to Marc Weustink: Dispose is the opposite of New. With New you can allocate dynamic variables like: var P:…
Show quoted text 25 lines
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: Type 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; end; PTrapezeInfo = ^TTrapezeInfo; Then, a TList called FTrapezes is created and items are added as: T := New(PTrapezeInfo); fTrapezes.Add(T); 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.
Dispose(PTrapezeInfo(FTrapezes[i]));

Reply by email