Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!rutgers!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!bg11+ From: bg11+@andrew.cmu.edu (Brian E. Gallew) Newsgroups: comp.lang.pascal Subject: Re: Findfirst Message-ID: Date: 13 Jul 90 16:28:12 GMT References: <23854@adm.BRL.MIL>, <4955@uwm.edu>, Organization: Carnegie Mellon, Pittsburgh, PA Lines: 124 In-Reply-To: I managed to fix the problem using some code someone sent me, but here is the buggy stuff: uses Crt,DOS; const DungeonPath = 'd:\tp\d&d\dmaze.???'; type FileNameListTypePtr = ^FileNameListType; FileNameListType = record Filerecord:SearchRec; Next:FileNameListTypePtr; end; var Head:FileNameListTypePtr; Function GetFileNameList(Firstlook:Boolean):FilenameListTypePtr; var Head:FileNameListTypePtr; begin New(Head); If Firstlook then FindFirst(DungeonPath,AnyFile,Head^.FileRecord) else FindNext(Head^.FileREcord); if DosError=0 then begin Head^.Next:=GetFileNameList(False); GetFileNameList:=Head; end else begin Dispose(Head); GetFileNameList:=Nil; end; end; Procedure LoseFileNameList(var Head:FileNameListTypePtr); begin if Head^.Next=Nil then Dispose(Head) else LoseFileNameList(Head^.Next); end; Procedure DrawList(Head:FileNameListTypePtr); var x:Integer; begin x:=0; clrscr; gotoxy(1,1); While Head<>Nil do begin Write(Head^.Filerecord.Name); x:=succ(x); Head:=Head^.Next; if x>4 then begin writeln; x:=0; end else gotoxy(x*16+1,WhereY); end; end; Function GetItem(head:FileNameListTypePtr; Which:Integer):FileNameListTypePtr; begin If (not (Head=Nil) and (Which<1)) then GetItem:=GetItem(Head^.Next,Which-1) else GetItem:=Nil; end; Function CountList(Head:FileNameListTypePtr):Integer; begin If Head=Nil then Countlist:=0 else Countlist:=1+CountList(Head^.Next); end; Function ShowFileNameList(var Head:FileNameListTypePtr):FileNameListTypePtr; var x,y,NewX,NewY,Count:integer; REady:Boolean; ch:Char; begin if Head<>Nil then begin Count:=CountList(Head); DrawList(Head); REady:=False; x:=0; y:=0; NewX:=0; NewY:=0; Repeat write(GetItem(Head,y*5+x)^.FileRecord.Name); ch:=Readkey; case ord(ch) of 0:begin ch:=ReadKey; case ord(ch) of 75:{cursor up}; 76:{cursor down}; 77:{cursor left}; 78:{cursor right}; 79:{home}; 80:{end}; end; end; 50:{cursor down}; 56:{cursor up}; 54:{cursor right}; 56:{cursor left}; 55:{home}; 49:{end}; 13:REady:=True; end; write(GetItem(Head,y*5+x)^.FileRecord.Name); x:=NewX; y:=NewY; until Ready; ShowFileNameList:=GetItem(Head,y*5+x); end else ShowFileNameList:=Nil end; begin Head:=GetFileNameList(True); Head:=ShowFileNameList(Head); Gotoxy(1,24);Write(Head^.FileRecord.Name); end.