Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to move stream memory to pointer...

779 views
Skip to first unread message

Anthony T.W.

unread,
Nov 26, 2002, 9:29:51 PM11/26/02
to
I want to move memory from a stream to a pointer... I am trying this.

MyStream := TMemoryStream.Create;
... write to stream ...

GetMem( MyPointer, MyStream.Size );
MyPointer^ := MyStream.Memory^;

But I get an error on the last line, saying "Operator not applicable to this
operand type". How else would I copy the memory?

--

Anthony Wertz (aka Anomy)
Webmaster, RPG Infinity
http://rpginfinity.com


Koms Bomb

unread,
Nov 26, 2002, 9:43:42 PM11/26/02
to
Try
MyStream.ReadBuffe(MyPointer, MyStream.Size);
'MyPointer^ := MyStream.Memory^;' not means copy the whole buffer.

--
Koms Bomb


*****Pardon my poor English*****
---------------------
Don't worry,be happy.

"Anthony T.W." <ano...@hotmail.com> wrote in message
news:3de42e96$1...@newsgroups.borland.com...

Renate Schaaf

unread,
Nov 26, 2002, 10:35:15 PM11/26/02
to
In article <3de42e96$1...@newsgroups.borland.com>, Anthony T.W. wrote:
> GetMem( MyPointer, MyStream.Size );
> MyPointer^ := MyStream.Memory^;
>

Use the ReadBuffer method of TMemoryStream. The ...^:=...^ only works
for typed pointers. The compiler needs to know how much to move.
Sometimes you can use typecasting as a way to move small chunks of
memory this way. But for a TMemoryStream, this is obviously not an
option.

Renate

John Herbster \(TeamB\)

unread,
Nov 26, 2002, 11:03:34 PM11/26/02
to
"Koms Bomb" <sends...@to.hell> wrote
> Try
> MyStream.ReadBuffer(MyPointer, MyStream.Size);

The method header is
procedure TStream.ReadBuffer(var Buffer; Count: Longint);
so I would use
MyStream.ReadBuffer(MyPointer^, MyStream.Size);
Regards, JohnH

Koms Bomb

unread,
Nov 27, 2002, 1:03:28 AM11/27/02
to
"John Herbster (TeamB)" <herb-sci at novus-tele.net> wrote in message
news:3de44425$1...@newsgroups.borland.com...

> The method header is
> procedure TStream.ReadBuffer(var Buffer; Count: Longint);
> so I would use
> MyStream.ReadBuffer(MyPointer^, MyStream.Size);
> Regards, JohnH

Yes, it's a mistake of mine.
I often confuse the usage of pointer in Delphi because it's a little strange
comparing to C.

AndyG

unread,
Nov 27, 2002, 7:52:44 AM11/27/02
to
In essense, just

move(MyStream.Memory^, MyPointer^, MyStream.Size);

"John Herbster (TeamB)" <herb-sci at novus-tele.net> wrote in message
news:3de44425$1...@newsgroups.borland.com...

Koms Bomb

unread,
Nov 27, 2002, 8:45:10 PM11/27/02
to
I'd been a C programmer for about 2 years, and I've just become a Delphi
programmer only for about four months.
Before I use Delphi, I even thought the object pascal syntax is strange and
didn't dare to study it, but now I think it's very beautiful. :-) Now I feel
very happy that I'm using Delphi instead of C.


--
Koms Bomb

*****Pardon my poor English*****
---------------------
Don't worry,be happy.

"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.0000969...@antispam.compuserve.com...


> In article <3de4...@newsgroups.borland.com>, Koms Bomb wrote:
> > I often confuse the usage of pointer in Delphi because it's a little
strange
> > comparing to C.
> >
>

> No, you get that wrong. The way C handles pointers is a bit strange
compared
> to Delphi <g>.
>
> --
> Peter Below (TeamB)
> Use the newsgroup archives :
> http://www.mers.com/searchsite.html
> http://www.tamaracka.com/search.htm
> http://groups.google.com
> http://www.prolix.be
>
>


0 new messages