Article View: borland.public.cppbuilder.internet.socket
Article #149Re: Hair 0, Indy10 1
From: Remy Lebeau (TeamB)
Date: Tue, 03 Jun 2008 20:37
Date: Tue, 03 Jun 2008 20:37
77 lines
3415 bytes
3415 bytes
"Gene Buckle" <geneb@grumble.deltasoft.com> wrote in message
news:4845a18d@newsgroups.borland.com...
> Is this, or is this not the correct way to use TIdTCPClient:
In general, yes. But earlier you showed that you are using it inside of a
classSimulator class. I'm more interested in seeing how THAT class is being
used. In particular, you also showed a call to ShowMessage(), but you did
not indicate WHERE that was being called from exactly. Can you please
provide a concrete compilable code snippet that demonstrates your problem in
a reproducable way?
> #include <IdIOHandlerStream.hpp>
Get rid of that one. You are not using it anymore.
> Client->Connect();
> connected = Client->Connected();
If Connect() fails, it will raise an exception. You do not need to call
Connected() immediately after Connect().
> FYI, attached is the only copy I have of the code that still shows
> the use of the TIdTCPClient component before I tore it out:
But you did not show how the classSimulator itself was being used.
> bool init_done;
You should always intialize your globals.
bool init_done = false;
> void __fastcall classSimulator::InitCommSystem() {
> if (!init_done) {
> busy = true;
> TCPClient = new TIdTCPClient(NULL);
> TCPClient->OnDisconnected = MainForm->DisconnectHandler;
>
> busy = false;
> init_done = true;
> }
> }
Where is TCPClient actually declared? Is it global, or is it a member of
classSimulator? Where is InitCommSystem() being called from?
> } catch (Exception &ex) {
You should always catch exceptions by 'const' reference instead:
} catch (const Exception &ex) {
> if (TCPClient->Connected()) {
> TCPClient->Disconnect();
You don't need to call Connected() first.
> void __fastcall classSimulator::CloseCommSystem() {
> TCPClient->Free();
> }
Where is CloseCommSystem() called from?
Never call Free() directly. Use 'delete' instead, especially since you used
'new' to allocate it. And be sure to reset your pointer back to NULL as
well:
void __fastcall classSimulator::CloseCommSystem()
{
delete TCPClient;
TCPClient = NULL;
}
Gambit
Technical Details
Message-ID:
<4845abc7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<48406d41@newsgroups.borland.com> <48407d4c$1@newsgroups.borland.com> <48408535@newsgroups.borland.com> <48442d6c$1@newsgroups.borland.com> <4845851e@newsgroups.borland.com> <48459486$1@newsgroups.borland.com> <4845a18d@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9339fc05f2f275c X-Google-Attributes: gid11508e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <48406d41@newsgroups.borland.com> <48407d4c$1@newsgroups.borland.com> <48408535@newsgroups.borland.com> <48442d6c$1@newsgroups.borland.com> <4845851e@newsgroups.borland.com> <48459486$1@newsgroups.borland.com> <4845a18d@newsgroups.borland.com> Subject: Re: Hair 0, Indy10 1 Date: Tue, 3 Jun 2008 13:37:34 -0700 Lines: 79 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <4845abc7$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1212525511 207.178.157.90 (3 Jun 2008 13:38:31 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail