🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages Started by Curt Sat, 13 Aug 2005 17:46
TIdThreadComponent
#3654
Author: Curt
Date: Sat, 13 Aug 2005 17:46
20 lines
1454 bytes
I added a TIdThreadComponent and a push button to a form.  When the button
is pressed the following code is executed to simply start and stop the
thread:

void __fastcall TForm1::cxButton1Click(TObject Sender)
{
  if (ThreadComponent1->Stopped == true) {
    ThreadComponent1->Start();
  } else {
    ThreadComponent1->Stop();
  }
  return;
}

This code works well when the TIdThreadComponent is initially set to
"Active=true" in the IDE however if the Active property is initially set to
"false" then I get an access violation.  Can someone please tell me why ?

Thank you,
Curt
Re: TIdThreadComponent
#3656
Author: Remy Lebeau (TeamB)
Date: Sat, 13 Aug 2005 19:37
16 lines
1518 bytes
"Curt" <noemailaddress> wrote in message
news:42fe315e@newsgroups.borland.com...

> This code works well when the TIdThreadComponent is initially
> set to "Active=true" in the IDE however if the Active property is
> initially set to "false" then I get an access violation.  Can someone
> please tell me why ?

You cannot access the Stopped property before Start() has been called.
Stopped accesses an internal TIdThread object that is created when Start()
is called.  The same goes for pretty much every other property and method of
TIdThreadComponent.  Call Start() first before accessing anything else.


Gambit
Re: TIdThreadComponent
#3657
Author: Curt
Date: Sat, 13 Aug 2005 20:20
29 lines
1987 bytes
>
> "Curt" <noemailaddress> wrote in message
> news:42fe315e@newsgroups.borland.com...
>
> > This code works well when the TIdThreadComponent is initially
> > set to "Active=true" in the IDE however if the Active property is
> > initially set to "false" then I get an access violation.  Can someone
> > please tell me why ?
>

> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:42fe4c66$3@newsgroups.borland.com...

> You cannot access the Stopped property before Start() has been called.
> Stopped accesses an internal TIdThread object that is created when Start()
> is called.  The same goes for pretty much every other property and method
of
> TIdThreadComponent.  Call Start() first before accessing anything else.
>
>
> Gambit
>
>

Great ! that works.  I put a call to Start() in Form1->OnCreate(), but I
want to have the thread "started" in a suspended state.  The best way I can
think of is to call Start() and then immediately call Stop() but I am
guessing that this is not the accepted way.
Re: TIdThreadComponent
#3658
Author: Remy Lebeau (TeamB)
Date: Sun, 14 Aug 2005 19:34
25 lines
1873 bytes
"Curt" <noemailaddress> wrote in message
news:42fe5578$1@newsgroups.borland.com...

> I put a call to Start() in Form1->OnCreate()

Do NOT use the OnCreate event in C++!!!  It is a Delphi remnant that can be
triggered before the constructor runs.  That is illegal behavior in C++.

> but I want to have the thread "started" in a suspended state.

Then don't call Start() at all until you are actually ready to run the
thread.  Or else do not use TIdThreadComponent at all.  Use TIdThread or
TThread directly instead.  The ONLY thing TIdThreadComponent offers is
design-time access to the events, which IMHO is not worth the hassle.  I few
extra lines of code to manage a thread manually can give you a LOT more
control over the thread.

> The best way I can think of is to call Start() and then immediately call
Stop()

That is NOT the best way to make a created a suspended thread.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads