stream read error when copying from memory stream to file stream

DSOM used Ask the Experts™
I have a tmemorystream and I want to copy it to a tfilestream but I am getting stream read error.

quick and dirty example:'c:\temp.tmp', fmcreate);, memstream.size);

Shouldn't this copy the contents of memstream to the filestream?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Martin BarredaPropietario asociado

From Delphi Help: "fmCreate      - ... If a file with the given name exists, open the file in write mode."
I understand that if it do not exists, the function only creates it but do not open it.
You should call
tfilestream.Create('c:\temp.tmp', fmcreate AND fmOpenWrite);
tfilestream.Create('c:\temp.tmp', fmcreate OR fmOpenWrite);
Something like this.
Hope this help!!
Senior Developer
make sure you do
  memstream.Seek(0, soFromBeginning);
before the
  new.Stream.CopyFrom(memstream, memstream.Size);


thanks TheRealLoki, that was the problem!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial