Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!mintaka!olivea!samsung!uakari.primate.wisc.edu!caen!uwm.edu!bionet!agate!usenet.ins.cwru.edu!po.CWRU.Edu!wct From: wct@po.CWRU.Edu (William C. Thompson) Newsgroups: comp.lang.pascal Subject: Re: Saving dynamic structures to disk & recalling revisited.... Message-ID: <1991Apr22.134725.27033@usenet.ins.cwru.edu> Date: 22 Apr 91 13:47:25 GMT References: <1991Apr22.085440.15582@usenet.ins.cwru.edu> Sender: news@usenet.ins.cwru.edu Reply-To: wct@po.CWRU.Edu (William C. Thompson) Organization: Case Western Reserve University, Cleveland, OH (USA) Lines: 78 Nntp-Posting-Host: cwns6.ins.cwru.edu In a previous article, wct@po.CWRU.Edu (William C. Thompson) says: I managed to fix my own problem... Here is the solution, though. >type > buffer=array[1..64000] of byte; > >procedure saveimage(x1,y1,x2,y2:word; fn:string; var size:word); >{ This procedure captures an image from the screen and writes > it to the specified file and returns the size. There is no error > checking as to how much memory is available. The size of an image > is the number of pixels divided by two plus 6 (VGA mode) } >var > f: file of byte; ^^^^^^^^^^^^ Change this to just plain FILE > p: ^buffer; > i: word; >begin > size:=imagesize(x1,y1,x2,y2); > getmem(p,size); { allocate space } > getimage(x1,y1,x2,y2,p^); { capture the image from screen } > assign(f,fn); > rewrite(f); > for i:=1 to size do write(f,p^[i]); { write image to disk } Replace these lines with rewrite(f,1) { tells compiler file's object size is 1 } blockwrite(f,p^,size,dummy) > freemem(p,size); { return memory } > close(f); >end; > >procedure recallimage(x1,y1:word; fn: string; size:word; wput:byte); >{ This procedure reads in an image from the specified file > and puts the image on the screen } >var > f: file of byte; ^^^^^^^^^^^^ Same here... > p: ^buffer; > i: word; >begin > getmem(p,size); { allocate space } > assign(f,fn); { prepare file } > reset(f); > for i:=1 to size do read(f,p^[i]); { read in the image } Replace these two lines by reset(f,1); blockread(f,p^,size,dummy) > close(f); > putimage(x1,y1,p^,wput); { put image on screen } > freemem(p,size); { return memory } >end; >The only drawback at all is that the part where I read from and >write to a file is slow. I tried BlockWrite and BlockRead, >but those made my files WAY too big. The file sizes didn't >match the number of bytes I told it to write. Here is the code >I used --- > >BlockRead(f,p^,size,n) & BlockWrite(f,p^,size,n) I think the main problem was that I didn't tell the compiler how big the file's objects were. Once I made that change, everything fell into place. -- Ticking away, the moments that make up a dull day. | William C. Thompson You fritter and waste the hours in an offhand way. | Michelson 620D (wct) Kicking around on a piece of ground in your hometown,| a.k.a. Master of Time, waiting for someone or something to show you the way.| Space, and Dimension