From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: Writing TMemoryStream to Memory-mapped file Date: 06 Oct 1999 00:00:00 GMT Message-ID: <3805a657.14034413@90.0.0.40> Content-Transfer-Encoding: 7bit References: <37FB7136.E5C609A5@tpmc.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.winapi On Wed, 06 Oct 1999 11:56:38 -0400, Gokhan Ergul wrote: >How do I copy the contents of a TMemoryStream after I opened a MMF and >getting a view to it? Use an intermediate buffer: procedure CopyStreamToFile(S: TStream; F: THandle); var BytesWritten: DWord; Buf: array[0..8191] of Byte; NumBytes: DWord; begin while S.Position < S.Size do begin NumBytes := S.Size - S.Position; if NumBytes > SizeOf(Buf) then NumBytes := SizeOf(Buf); S.Read(Buf, NumBytes); WriteFile(F, Buf, NumBytes, BytesWritten, nil) end end; With a TMemoryStream, it's actually possible to avoid using a buffer, but the above code has the advantage of working with any kind of stream. -Steve