Board index » delphi » Array of TList. Adding and removing - HELP

Array of TList. Adding and removing - HELP

I have an array of TLists.  Inside of the lists I have a number of Doubles
(pointers to).  I was wondering if  what Im doing is wrong becasue Im
getting some funny results.

Here is what Im doing essentially.  The next step is to move from bucket to
bucket and
extract the (sorted) values.  This isn't working.  I keep getting alternate
weird results.  Am I doing anything really weird?  If someone could PLEASE
fix this.  Some code that shows a listing of all the values in bucket 100
say would be perfect.  Im not used to Delphi pointers at all  :(

thanx
James

PS:  please post back to here.

 ---snippet---
procedure TEdge.ScanConvert(X1,Y1,X2,Y2:Integer);
var
    x : Double;
    count : Integer;
begin

  -snip-
   x = X1;
   m = (X2-X1)/(Y2-Y1);
   for count := Y1 to Y2 do
   begin
        bucket[count].Add(@x);
        x := x + m;
        bucket[count].Sort(compare);
   end

end;

 

Re:Array of TList. Adding and removing - HELP


All entries in your list are the same, since you are "adding" always the
pointer to x (-> @x).

Alex
--
*** http://www.bullterrier-in-not.de/massenmord.htm ***

Author of the free Chatsystem PINO!
Available at http://pino.cjb.net

Re:Array of TList. Adding and removing - HELP


procedure TEdge.ScanConvert(X1,Y1,X2,Y2:Integer);
var
    y, x : ^ Double;
    count : Integer;
begin

  -snip-
   New (x);
   x^ = X1;
   m = (X2-X1)/(Y2-Y1);
   for count := Y1 to Y2 do
   begin
        bucket[count].Add(x);
        y := x;
        New (x);
        x^ := y^ + m;
        bucket[count].Sort(compare);
   end

When you are finished with one of the elements in the list you must do
Dispose (bucket [count]) before removing the entry from the list. Otherwise
your program will leak like a sieve.

Re:Array of TList. Adding and removing - HELP


WOOHOO :)

I realised that my pointers were all screwed up, but I wasn't sure on how to
fix it.  It works great now.  Thanks so much for the reply's

James

Other Threads