Board index » delphi » TIdCommandHandler.OnCommand and form creation: freeze!?

TIdCommandHandler.OnCommand and form creation: freeze!?


2003-11-06 10:41:48 PM
delphi283
Hi all,
I've been poring over Google and GoogleGroups results for a while, and
perusing the past 1,500 posts in here, but didn't find an answer.
The deal is quite simple.
I've got an app that sort of mimics mIRC's window behavior. When it gets a
certain command, the command handler's OnCommand event handler triggers
and, if necessary, creates a new form (that happens to be an MDIChild,
which might be relevant?!). The very line:
QueryForm := TfrmQuery.Create(Application);
freezes my app.
I haven't yet tried to figure out the considerable depths of Indy's
behavior leading up to this event handler, which might eventually provide
me with some thread/sync clue, but I assume Indy developers or experts
might help me out here.
What's going on? What's inside Indy that makes MDI form creation an issue?
Do I need some Synchronize call on the current Indy thread, thereby
needing to deport relevant info somewhere since the called method must be
no-arg?
--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"With sufficient thrust, pigs fly just fine"
 
 

Re:TIdCommandHandler.OnCommand and form creation: freeze!?

The first thing i notice is that your creating the form passing the
application as the params. I am not sure how well that will work.. You can
pass a NIL parameter as long as you make sure that you do a QueryForm.Free
when you are done using it or
memory leask may occur.
QueryForm := TfrmQuery.Create(NIL);
...
...
QueryForm.Free;
"Christophe Porteneuve" <XXXX@XXXXX.COM>writes
Quote
Hi all,

I've been poring over Google and GoogleGroups results for a while, and
perusing the past 1,500 posts in here, but didn't find an answer.

The deal is quite simple.

I've got an app that sort of mimics mIRC's window behavior. When it gets a
certain command, the command handler's OnCommand event handler triggers
and, if necessary, creates a new form (that happens to be an MDIChild,
which might be relevant?!). The very line:

QueryForm := TfrmQuery.Create(Application);

freezes my app.

I haven't yet tried to figure out the considerable depths of Indy's
behavior leading up to this event handler, which might eventually provide
me with some thread/sync clue, but I assume Indy developers or experts
might help me out here.

What's going on? What's inside Indy that makes MDI form creation an issue?
Do I need some Synchronize call on the current Indy thread, thereby
needing to deport relevant info somewhere since the called method must be
no-arg?

--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"With sufficient thrust, pigs fly just fine"

 

Re:TIdCommandHandler.OnCommand and form creation: freeze!?

"I've got an app that sort of mimics mIRC's window behavior. When it gets a
Quote
certain command, the command handler's OnCommand event handler triggers
and, if necessary, creates a new form (that happens to be an MDIChild,
which might be relevant?!). The very line:

QueryForm := TfrmQuery.Create(Application);

freezes my app.
Yes. You need to create the form in the context of the main thread.
Quote
I haven't yet tried to figure out the considerable depths of Indy's
behavior leading up to this event handler, which might eventually provide
me with some thread/sync clue, but I assume Indy developers or experts
might help me out here.
There is none. The command handlers run in the context of the peer thread.
Quote
What's going on? What's inside Indy that makes MDI form creation an issue?
It's an issue with any form creation, or indeed, with many VCL operations.
Quote
Do I need some Synchronize call on the current Indy thread, thereby
needing to deport relevant info somewhere since the called method must be
no-arg?
Well, a synchronized method is a method of the thread & so can fill in
thread fields with, say, a MDI form reference. You can use the form ref. in
later 'synchronize', 'sendMessage' or 'postMessage' calls. Similarly, the
synchronized method could fill in a form field with the thread reference, so
giving it access to the 'send' methods of the thread connection. You will
probably have to do some extra twiddling when the client disconnects - free
the form etc.
You should also look at the Indy TidNotify and TidSync classes - these
provide a X-platform alternative to the 'normal' Win32 API thread comms
methods & the 'synchronize' method.
Rgds,
Martin
 

Re:TIdCommandHandler.OnCommand and form creation: freeze!?

"Christophe Porteneuve" <XXXX@XXXXX.COM>writes
Quote
The very line:

QueryForm := TfrmQuery.Create(Application);

freezes my app.
The OnCommand event is triggered in the context of a worker thread, not the
main thread. However, VCL forms need to be in the main thread instead.
From the OnCommand event handler, you can get access to the particular
TIdPeerThread that it is running in, and from there use Synchronize() to
make sure the form creation is occuring in the main thread, not the worker
thread.
Quote
Do I need some Synchronize call on the current Indy thread
Yes.
Gambit