Link to home
Start Free TrialLog in
Avatar of DSOM
DSOMFlag for United States of America

asked on

stream read error when copying from memory stream to file stream

I have a tmemorystream and I want to copy it to a tfilestream but I am getting stream read error.

quick and dirty example:

new.stream:=tfilestream.Create('c:\temp.tmp', fmcreate);
new.stream.copyfrom(memstream, memstream.size);

Shouldn't this copy the contents of memstream to the filestream?
Avatar of Martin Barreda
Martin Barreda
Flag of Argentina image

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);
or
tfilestream.Create('c:\temp.tmp', fmcreate OR fmOpenWrite);
Something like this.
Hope this help!!
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DSOM

ASKER

thanks TheRealLoki, that was the problem!