Hi, all
I just upgraded to a more recent version of GPC, 2001something. I don't know if that's the root cause, but I'm having trouble killing a linked list. I get a page fault or a GPF (I'm running under win98) when trying to delete the last or next to last record. I've marked the line named in the call traceback.
I took my Linsert and Lwipe procedures and put them into a test program (see below). It runs perfectly. But when I run them in the program I'm actually working on -- the program I took the procedures from -- it crashes in Lwipe. Nothing else in the big program even refers to the list. Any suggestions?
It's frustrating to be stopped on such an elementary problem. Lists and I have been friends for years, and I'm supposed to be stuck on much more interesting problems!
Toby _____________________________
Program ListTest;
type PRec = ^Rec; Rec = record ri : integer; Next : PRec; end;
var Root : PRec; i : integer; {----------}
Procedure LWipe(var Root : PRec); var point : PRec; begin while (Root^.next <> Nil) do begin {<<== program crashes on this line} write('deleting ', root^.ri, ' '); point := Root; Root := Root^.next; Dispose(point); end; if Root <> Nil then begin write('deleting ', root^.ri); Dispose(Root); Root := Nil; end; end; {----------}
Procedure LInsert(var num : integer; var Root : PRec); {insert a new record at the *front* of the list} var Site : Rec; temp : PRec; begin with Site do begin ri := num; next := Nil; end; if Root = Nil then begin {starting the list} New(Root); Root^ := Site; end else begin {list already exists} New(temp); {get new memory} temp^ := Site; {move memory} temp^.next := Root; {repoint pointers} Root := temp; end; end; {LInsert} {----------}
Begin for i := 1 to 100 do LInsert(i, Root); LWipe(Root); End.