Board index » cppbuilder » TForms not working correctly from in a TThread

TForms not working correctly from in a TThread

Ok... I've create a TThreadObj called UIThread. In the Execute when
certain events occur I create TForms. On NONE of the TForms the TAB key
doesn't work to go from field to Field.
Note that I've added the PeekMessage and Translate/Dispatch Message.
Which without the forms don't even draw..

void __fastcall UIThread::Execute()
{

    while (keep_going == true)
    {
       while(PeekMessage(&windows_message,NULL,0,0,PM_REMOVE))
        {
            if (windows_message.message==WM_QUIT)
            {
                continue;
            }

      TranslateMessage(&windows_message);
      DispatchMessage(&windows_message);
        }

    .
    .
    .
    If (SOMECASE) {
        tMYFORM *TMF = new tMYFORM();
        TMF->SHOW();
    }

Quote
}

 

Re:TForms not working correctly from in a TThread


Hi, Bill!

What are the forms parented to / owned by?

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TForms not working correctly from in a TThread


Most Application.MainForm (Which is in another thread) others are set to
NULL... All normal key strokes work and so does the mouse... It's just
that tab key doesn't work (It just beeps)
Quote
"Mark Cashman (TeamB)" wrote:
> Hi, Bill!

> What are the forms parented to / owned by?

> ------
> Mark Cashman, TeamB C++ Builder
> http://www.temporaldoorway.com/programming/index.htm
> C++ Builder, JBuilder programming information
> Home of The C++ Builder Programmer's Webring - Join us!
> ------

Re:TForms not working correctly from in a TThread


On Fri, 29 Sep 2000 12:15:15 -0600, Bill Nortman

Quote
<bill.nort...@modinst.com> wrote:
>Ok... I've create a TThreadObj called UIThread. In the Execute when
>certain events occur I create TForms.

You can't do that unless you use Synchronize() - all VCL activity must
be in the main thread.
Why create a UI thread? The primary purpose of the main thread is to
manage the user interface by handling Windows messages; you should be
creating secondary threads for time-comsuming tasks which _don't_
manipulate the user interface.

Re:TForms not working correctly from in a TThread


You can... create them it works... the only thing that doesn't work is the
TAB Key for skipping fields automatically... although I can do it manually
in the Key Pressed Event.

Why to do this.. Well long story but the basic idea is...  A computational
thread requires data from Main Thread and the Dialogs need data from the
computational thread... if the Dialogs and the Main GUI where in
the same thread it would lock up..

Quote
Michael Warner wrote:
> On Fri, 29 Sep 2000 12:15:15 -0600, Bill Nortman
> <bill.nort...@modinst.com> wrote:

> >Ok... I've create a TThreadObj called UIThread. In the Execute when
> >certain events occur I create TForms.

> You can't do that unless you use Synchronize() - all VCL activity must
> be in the main thread.

> Why create a UI thread? The primary purpose of the main thread is to
> manage the user interface by handling Windows messages; you should be
> creating secondary threads for time-comsuming tasks which _don't_
> manipulate the user interface.

Re:TForms not working correctly from in a TThread


On Mon, 02 Oct 2000 08:27:44 -0600, Bill Nortman

Quote
<bill.nort...@modinst.com> wrote:
>Why to do this.. Well long story but the basic idea is...  A computational
>thread requires data from Main Thread and the Dialogs need data from the
>computational thread... if the Dialogs and the Main GUI where in
>the same thread it would lock up..

Because of the way you've implemented data passing between the
threads. That's the problem you should be telling us about.

Re:TForms not working correctly from in a TThread


Hi, Bill!

If you need to share data like this, it's better to have a model class
for the data and have that class provide accessor methods which use a
critical section to prevent conflicting access to the data. Indeed, if
you provide access to the data via properties with such accessors, your
code won't even know about the exclusion, but will get the benefit.

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TForms not working correctly from in a TThread


Critical Sections are WAY to slow....instead we've created a strict client
server method so we can post and get data from our various threads.
Additionally I want my dialogs to operated independently from the main
GUI. Our machine make measurements the require <50MS updates.

The problem I was having was just the fact that when running the TForm in a
TThread the TAB key doesn't automatically work. I've worked around it by
using the KEYPRESSED event
and selecting the next component.

Quote
"Mark Cashman (TeamB)" wrote:
> Hi, Bill!

> If you need to share data like this, it's better to have a model class
> for the data and have that class provide accessor methods which use a
> critical section to prevent conflicting access to the data. Indeed, if
> you provide access to the data via properties with such accessors, your
> code won't even know about the exclusion, but will get the benefit.

> ------
> Mark Cashman, TeamB C++ Builder
> http://www.temporaldoorway.com/programming/index.htm
> C++ Builder, JBuilder programming information
> Home of The C++ Builder Programmer's Webring - Join us!
> ------

Other Threads