 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bruce McGee Guest
|
Posted: Tue Apr 13, 2004 4:03 pm Post subject: Indy 10 ContextClass example |
|
|
Does anyone have a simple IDTCPServer example that uses ContextClass?
I'm trying to get my head around the differences between this and how I
use ThreadClass in Indy 9.
For example, with the ThreadClass, I would create the thread suspended
(override constructor), set any properties in the IDTCPServer's
OnConnect event and resume the thread when I'm ready. I'm not sure
this still applies.
Any help is appreciated.
Regards,
Bruce McGee
Glooscap Software
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Apr 13, 2004 7:14 pm Post subject: Re: Indy 10 ContextClass example |
|
|
"Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote
| Quote: | For example, with the ThreadClass, I would create the thread
suspended (override constructor), set any properties in the
IDTCPServer's OnConnect event and resume the thread when
I'm ready. I'm not sure this still applies.
|
Why were you doing that to begin with? You should have been setting your
values in the overriden constructor itself and not suspending the thread at
all.
Gambit
|
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Mon Apr 19, 2004 6:20 pm Post subject: Re: Indy 10 ContextClass example |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote in message
news:xn0dgz1x8sr0guu000 (AT) newsgroups (DOT) borland.com...
For example, with the ThreadClass, I would create the thread
suspended (override constructor), set any properties in the
IDTCPServer's OnConnect event and resume the thread when
I'm ready. I'm not sure this still applies.
Why were you doing that to begin with? You should have been setting
your values in the overriden constructor itself and not suspending
the thread at all.
Gambit
|
Sorry for the delay getting back to you.
The values I want to set in the thread come from an external source.
In this case, the form. I don't want the thread to know about (for
example) a check box on the form, and I don't know of a way to call an
overloaded constructor for my TIdPeerThread to pass in the arguments.
I also want to set these values before OnExecute is run.
The only way I could think to do this was create the thread in a
suspended state set the thread's properties in the OnConnect event and
then call Resume.
1) How would you do the same thing?
If you do, then I think I can use the ContextClass exactly the same way
I used ThreadClass.
--
Regards,
Bruce McGee
Glooscap Software
|
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Tue Apr 20, 2004 6:16 pm Post subject: Re: Indy 10 ContextClass example |
|
|
At first glance, you might think that OnBeforeConnect would be the ideal
place, but this event never seems to fire.
--
Regards,
Bruce McGee
Glooscap Software
|
|
| Back to top |
|
 |
Chad Z. Hower aka Kudzu Guest
|
Posted: Tue Apr 20, 2004 6:44 pm Post subject: Re: Indy 10 ContextClass example |
|
|
"Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote in news:xn0dh90tl0000000
@newsgroups.borland.com:
| Quote: | At first glance, you might think that OnBeforeConnect would be the ideal
place, but this event never seems to fire.
|
The two arent connected. If you have a custom context, make sure you are
calling all the inherited items.
OnBeforeConnect should be firing, if not its a bug.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Got Indy? Got the book?
http://www.atozed.com/indy/book/
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Apr 20, 2004 8:08 pm Post subject: Re: Indy 10 ContextClass example |
|
|
"Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote
| Quote: | The only way I could think to do this was create the
thread in a suspended state set the thread's properties
in the OnConnect event and then call Resume.
|
Setting the thread initially suspended as no effect, as TIdTCPServer always
resumes threads automatically when a new connection is accepted. As soon as
you enter the OnConnect event, the thread is already running, thus there is
no need to resume it.
Gambit
|
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Fri Apr 30, 2004 2:14 pm Post subject: Re: Indy 10 ContextClass example |
|
|
Chad Z. Hower aka Kudzu wrote:
| Quote: | The two arent connected. If you have a custom context, make sure you
are calling all the inherited items.
OnBeforeConnect should be firing, if not its a bug.
|
I usually call inherited, but I'll be sure to make a point of it.
How do you mean they aren't connected? If I wanted to do something
with the Context before OnExecute fires, where would the best place be?
In a quick test, OnBeforeConnect doesn't appear to fire, so there might
be a bug, but I'd be happy to be wrong. Here's what I did:
- New project
- Drop a TIdTCPServer on the form
- Put some code in OnExecute. I just listen for a character and echo
it back.
- Put some code in OnBeforeConnect to see if it fires. I used CodeSite.
OnExecute fires fine, but OnBeforeConnect doesn't. Just to be safe, I
also made sure to grab the latest snapshot this morning.
Another small thing. Adding the IdTCPServer to the from doesn't add
IdContext to the Uses clause, and I have to add it manually.
--
Regards,
Bruce McGee
Glooscap Software
|
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Fri Apr 30, 2004 2:14 pm Post subject: Re: Indy 10 ContextClass example |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | Setting the thread initially suspended as no effect, as TIdTCPServer
always resumes threads automatically when a new connection is
accepted. As soon as you enter the OnConnect event, the thread is
already running, thus there is no need to resume it.
|
Whoops.
Fair enough. I'll rethink this a little.
--
Regards,
Bruce McGee
Glooscap Software
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|