Article View: borland.public.cppbuilder.internet.socket
Article #5260Re: How can I send a TBitmap from Client application to Server application
From: Mark Jacobs
Date: Mon, 27 Sep 2004 20:28
Date: Mon, 27 Sep 2004 20:28
39 lines
3180 bytes
3180 bytes
Because the ServerSocket1->Socket->Connections[0]->SendStream(SendPms); deletes
the stream for you. This is from the BCB component help file description :-
-------------------------------------------------
TCustomWinSocket::SendStream
bool __fastcall SendStream(Classes::TStream* AStream);
Use SendStream to write to the socket connection. SendStream may write from a
socket that is expected to write to the connection without a notification to
signal the connection's readiness to read. SendStream reads information from the
stream indicated by AStream and writes it to the socket connection. The value
returned by SendStream indicates whether any information was successfully
written to the connection.
Note: The Stream passed as a parameter to SendStream becomes "owned" by the
windows socket object. The Windows socket object frees the stream when it is
finished with it. Do not attempt to free the stream after it has been passed as
a parameter.
-------------------------------------------------
The salient point is, "The Windows socket object frees the stream when it is
finished with it. Do not attempt to free the stream after it has been passed as
a parameter." So, take out the delete line - there will be no memory leak.
--
Mark Jacobs
"Byanex" <chikui@bol.com.br> wrote in message
news:41586e5b$1@newsgroups.borland.com...
| One more thing, the server code below presents some acces violation errors
code when run with "delete" line, any one know why???
| void __fastcall TForm1::Button1Click(TObject *Sender)
| {
| TMemoryStream* SendPms = new TMemoryStream();
| Image1->Picture->Bitmap->SaveToStream(SendPms);
| SendPms->Position=0;
| ServerSocket1->Socket->Connections[0]->SendStream(SendPms);
| delete SendPms; // <<-- This line
| }
|
| Without the delete line the code runs fine, any problem if just take out this
line???
Technical Details
Message-ID:
<415877e1$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<407e54f8$1@newsgroups.borland.com> <407e66c5@newsgroups.borland.com> <407ec9c7@newsgroups.borland.com> <415080c1$1@newsgroups.borland.com> <415087be$1@newsgroups.borland.com> <41586e5b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b60555b8e5a57a55 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?Borland%20Newsgroup> Newsgroups: borland.public.cppbuilder.internet.socket References: <407e54f8$1@newsgroups.borland.com> <407e66c5@newsgroups.borland.com> <407ec9c7@newsgroups.borland.com> <415080c1$1@newsgroups.borland.com> <415087be$1@newsgroups.borland.com> <41586e5b$1@newsgroups.borland.com> Subject: Re: How can I send a TBitmap from Client application to Server application Date: Mon, 27 Sep 2004 21:28:11 +0100 Lines: 40 Organization: DK Computing MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 81.86.186.94 Message-ID: <415877e1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096316897 81.86.186.94 (27 Sep 2004 13:28:17 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail