Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!portal!cup.portal.com!R_Tim_Coslet From: R_Tim_Coslet@cup.portal.com Newsgroups: comp.lang.pascal Subject: Re: Pointers.. Message-ID: <18940@cup.portal.com> Date: 29 May 89 23:57:14 GMT References: <3398@westfort.UUCP> Organization: The Portal System (TM) Lines: 51 In article: <3398@westfort.UUCP> dragon@westfort.UUCP (The Mystic) Writes... > >Program testheap; > >uses dos,crt; > >Type > boardtype=^boardrec; <-- a POINTER type > boardrec=record >name:string[20]; >age:integer; >end; >Var > msgbase:boardtype; > messagebase:file of boardtype; <-- this is a file of POINTERS !?!?! > >procedure getest; >begin [deleted] > write(messagebase,msgbase); <-- notice he ONLY wrote the POINTER! > close(messagebase); >end; > >procedure readtest; >begin [deleted] >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? Very simple... the records were not saved, only the pointers. You will notice that the "messagebase" file is ONLY a file of pointers. These pointers are pointers to memory locations, which when the program is run as originally written were created by the call to "getest" and happen to still exist when "readtest" is called. However if "getest" is taken out the records do not exist when "readtest" is called. In my opinion you should NEVER write a file containing pointer variables (or pointer fields of records): pointers are addresses in memory... and those memory locations may (probably will) contain other data when the file finally gets read again (even if the data was also saved in a file). R. Tim Coslet Usenet: R_Tim_Coslet@cup.portal.com BIX: r.tim_coslet