Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Problem reading data from TidIOHandler
| Subject: | Re: Problem reading data from TidIOHandler |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 14 Aug 2006 10:44:45 |
"Kiwi" <glen@custommadesoftware.co.nz> wrote in message
news:44dfe6d2@newsgroups.borland.com...
> IOHandler.ReadBytes(Buf, 1, False);
Use ReadByte() instead:
Size := IOHandler.ReadByte;
> IOHandler.ReadBytes(Buf, Size, False);
Use ReadStream() instead:
fMem.Clear;
IOHandler.ReadStream(fMem, Size, False);
> BytesToRaw(Buf, fMem, Size);
> fMem.Seek(0,soFromBeginning); <==== I get a EAccessViolation.
You are trying to write your data to the memory address where the stream
object itself resides, not to the memory address where the stream stores its
data buffer. You are not writing the data into the stream at all. To do
that, you would have to set the stream's Size property (to preallocate the
buffer to the proper size), and then write the data into the stream's Memory
property, ie:
fMem.Size := Size;
BytesToRaw(Buf, fMem.Memory, Size);
> I seem to always end up with problems using streams
You aren't using them properly.
Gambit