Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!unido!pbinfo!corona!pgcomp From: pgcomp@pbinfo.UUCP (Projektgr. Uebersetzerbau) Newsgroups: comp.lang.pascal Subject: Re: Pointers.. Message-ID: <537@corona.pb> Date: 30 May 89 09:02:43 GMT References: <3398@westfort.UUCP> Organization: Uni-GH Paderborn, Germany Lines: 62 In article <3398@westfort.UUCP>, dragon@westfort.UUCP (The Mystic) writes: ] ] I managed to get pointers working w/ files, yet for some reason when I ] come back to the file, it's all garbage.. I realize that the pointers were for ] memory vars only, but this program created a disk file as I specified in my ] assign command.. Perhaps an example.. ] ] Program testheap; ] ] uses dos,crt; ] ] Type ] boardtype=^boardrec; ] boardrec=record ] name:string[20]; ] age:integer; ] end; ] Var ] msgbase:boardtype; ] messagebase:file of boardtype; ] ] procedure getest; ] begin ] clrscr; ] write('Enter Your Name: '); readln(msgbase^.name); ] write('Enter Your Age.: '); readln(msgbase^.age); ] assign(messagebase,'c:\pascal\testfile.dat'); ] {$I-} reset(messagebase); {$I+} ] if ioresult<>0 then rewrite(messagebase); ] write(messagebase,msgbase); ] close(messagebase); ] end; ] ] procedure readtest; ] begin ] assign(messagebase,'c:\pascal\testfile.dat'); ] writeln; ] {$I-} reset(messagebase); {$I+} ] if ioresult<>0 then rewrite(messagebase); ] read(messagebase,msgbase); ] with msgbase^ do begin ] writeln('Your name is: ',name); ] writeln('Your Age is.: ',age); ] delay(5000); ] close(messagebase); ] end; ] end; ] ] begin getest; readtest; end. ] ] If I take out the getest from the routine, after I've run other programs, it ] brings up garbage... Why? Didn't you remember the difference between pointers and variables ? You declared msgbase as a pointer to boardrec, but you didn't allocate (* new(msgbase) *) any memory space for holding an element of type boardrec. Thus any operation with msgbase must fail due to writing in nonallocated memory space. thomas roemke (tt)