Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages
Started by James L. Williams
Sat, 14 Jun 2008 15:17
VCL Form inside TThread->Execute
Author: James L. Williams
Date: Sat, 14 Jun 2008 15:17
Date: Sat, 14 Jun 2008 15:17
36 lines
1800 bytes
1800 bytes
Hello,
I would like to create a form that exists inside a Thread. I want this so
that the forms graphics updates are handled inside of a thread.
I do something like the following:
Thread::Execute()
{
MSG msg;
TmyForm * myForm = new TmyForm(NULL);
myForm->Parent = NULL;
myForm->ParentWindow = GetDesktopWindow();
myForm->Left = 10;
myForm->Top = 10;
myForm->Width = 500;
myForm->Height = 500;
myForm->Visible = true;
while(GetMessage(msg,NULL,0,0))
{
if(Terminated) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
delete myForm;
}
Is this a good way to do it, or is there a better way?
Thanks,
James
Re: VCL Form inside TThread->Execute
Author: Ed Mulroy [TeamB]
Date: Sat, 14 Jun 2008 15:46
Date: Sat, 14 Jun 2008 15:46
41 lines
2325 bytes
2325 bytes
For reliability and best performance VCL visuals are best handled in a
single thread as the VCL does not contain elements to by default handle
intra-thread issues. My opinion is that you should post something to the
main thread for that form.
To get others' opinions post to a group which better relates to the subject
of your message. This group might be a good one to post in:
borland.public.cppbuilder.vcl.components.using
. Ed
> James L. Williams wrote in message
> news:4853e32c$1@newsgroups.borland.com...
>
> I would like to create a form that exists inside a Thread. I want this so
> that the forms graphics updates are handled inside of a thread.
>
> I do something like the following:
>
> Thread::Execute()
> {
> MSG msg;
> TmyForm * myForm = new TmyForm(NULL);
> myForm->Parent = NULL;
> myForm->ParentWindow = GetDesktopWindow();
> myForm->Left = 10;
> myForm->Top = 10;
> myForm->Width = 500;
> myForm->Height = 500;
> myForm->Visible = true;
> while(GetMessage(msg,NULL,0,0))
> {
>
> if(Terminated) break;
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
> delete myForm;
> }
>
> Is this a good way to do it, or is there a better way?
Re: VCL Form inside TThread->Execute
Author: James
Date: Sat, 14 Jun 2008 17:45
Date: Sat, 14 Jun 2008 17:45
60 lines
3130 bytes
3130 bytes
I would, except that the application that uses this thread form in not a C++
Builder application. In fact, it does not have its own support for
multi-thread, however it does allow dll calls.
Hence, I decided to wrap up a form object into a thread and place that into
a dll. Then they can create an instance and the form runs. The reason I
need this is because in their main application they may be executing a
lengthy database query. I wanted to provide a progress bar that shows that
the application has not hung, but is retrieving data. They also want to use
this when they download files, to indicate things are going well.
Thanks,
James
"Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message
news:4853e7cb$1@newsgroups.borland.com...
> For reliability and best performance VCL visuals are best handled in a
> single thread as the VCL does not contain elements to by default handle
> intra-thread issues. My opinion is that you should post something to the
> main thread for that form.
>
> To get others' opinions post to a group which better relates to the
> subject of your message. This group might be a good one to post in:
> borland.public.cppbuilder.vcl.components.using
>
> . Ed
>
>> James L. Williams wrote in message
>> news:4853e32c$1@newsgroups.borland.com...
>>
>> I would like to create a form that exists inside a Thread. I want this
>> so that the forms graphics updates are handled inside of a thread.
>>
>> I do something like the following:
>>
>> Thread::Execute()
>> {
>> MSG msg;
>> TmyForm * myForm = new TmyForm(NULL);
>> myForm->Parent = NULL;
>> myForm->ParentWindow = GetDesktopWindow();
>> myForm->Left = 10;
>> myForm->Top = 10;
>> myForm->Width = 500;
>> myForm->Height = 500;
>> myForm->Visible = true;
>> while(GetMessage(msg,NULL,0,0))
>> {
>>
>> if(Terminated) break;
>> TranslateMessage(&msg);
>> DispatchMessage(&msg);
>> }
>> delete myForm;
>> }
>>
>> Is this a good way to do it, or is there a better way?
>
>
Re: VCL Form inside TThread->Execute
Author: Ed Mulroy [TeamB]
Date: Sat, 14 Jun 2008 18:13
Date: Sat, 14 Jun 2008 18:13
25 lines
2170 bytes
2170 bytes
That means the only GUI VCL code is in a certain thread. So the requirements MAY have been met, that all GUI VCL items are in the same thread. I don't see a message from you in b.p.c.vcl.components.using, and that is the place where people who have done things like this are found. I strongly recommend that you post in there and when you do, mention what you only said in your reply, that the application is not a BCB one. . Ed > James wrote in message > news:485403a7@newsgroups.borland.com... > > I would, except that the application that uses this thread form in not a > C++ Builder application. In fact, it does not have its own support for > multi-thread, however it does allow dll calls. > > Hence, I decided to wrap up a form object into a thread and place that > into a dll. Then they can create an instance and the form runs. The > reason I need this is because in their main application they may be > executing a lengthy database query. I wanted to provide a progress bar > that shows that the application has not hung, but is retrieving data. They > also want to use this when they download files, to indicate things are > going well.
Re: VCL Form inside TThread->Execute
Author: James
Date: Sat, 14 Jun 2008 18:26
Date: Sat, 14 Jun 2008 18:26
38 lines
2745 bytes
2745 bytes
I did post this in the b.p.c.vcl.components.using. It was posted yesturday with the same subject heading. Also, I suppose that means that I can't have multiple instances of the thread class. I.E. I can't create several at once and have multiple threads with their own Message handlers. Is this correct? Thanks. "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message news:48540a59$1@newsgroups.borland.com... > That means the only GUI VCL code is in a certain thread. So the > requirements MAY have been met, that all GUI VCL items are in the same > thread. > > I don't see a message from you in b.p.c.vcl.components.using, and that is > the place where people who have done things like this are found. I > strongly recommend that you post in there and when you do, mention what > you only said in your reply, that the application is not a BCB one. > > . Ed > >> James wrote in message >> news:485403a7@newsgroups.borland.com... >> >> I would, except that the application that uses this thread form in not a >> C++ Builder application. In fact, it does not have its own support for >> multi-thread, however it does allow dll calls. >> >> Hence, I decided to wrap up a form object into a thread and place that >> into a dll. Then they can create an instance and the form runs. The >> reason I need this is because in their main application they may be >> executing a lengthy database query. I wanted to provide a progress bar >> that shows that the application has not hung, but is retrieving data. >> They also want to use this when they download files, to indicate things >> are going well. > >
Re: VCL Form inside TThread->Execute
Author: Ed Mulroy [TeamB]
Date: Sat, 14 Jun 2008 21:32
Date: Sat, 14 Jun 2008 21:32
21 lines
2024 bytes
2024 bytes
I don't think you can create multiple threads in each of which you have a VCL form and message handler. You could do it with the Windows API but would still probably run across some inter-thread issues. You also have yet another problem. I am not really a VCL guy. I do most GUI things using the Windows API and mostly only use the VCL for quicky demos. There are guys who know the VCL from the inside out and they hang out in that other group. I'll try to see if I can get one of them to look at your message over there. . Ed > James wrote in message > news:48540d41$1@newsgroups.borland.com... > >I did post this in the b.p.c.vcl.components.using. It was posted yesturday >with the same subject heading. > > Also, I suppose that means that I can't have multiple instances of the > thread class. I.E. I can't create several at once and have multiple > threads with their own Message handlers. Is this correct?
Re: VCL Form inside TThread->Execute
Author: danzer
Date: Mon, 16 Jun 2008 14:48
Date: Mon, 16 Jun 2008 14:48
16 lines
1951 bytes
1951 bytes
James wrote: > I would, except that the application that uses this thread form in not a C++ > Builder application. In fact, it does not have its own support for > multi-thread, however it does allow dll calls. > > Hence, I decided to wrap up a form object into a thread and place that into > a dll. Then they can create an instance and the form runs. The reason I > need this is because in their main application they may be executing a > lengthy database query. I wanted to provide a progress bar that shows that > the application has not hung, but is retrieving data. They also want to use > this when they download files, to indicate things are going well. > Have you considered having the thread do the "length database query" and posting status messages to the main application? I have used this method and it works quite well.
Re: VCL Form inside TThread->Execute
Author: James Williams
Date: Mon, 16 Jun 2008 15:40
Date: Mon, 16 Jun 2008 15:40
32 lines
2706 bytes
2706 bytes
There lies the problem. The application that is used to develope the database client is not multi thread capable at all. So the query must reside in the main application thread. Hence the need to have a form created in the Thread->Execute method and allow the progress bar to work under that thread. I have gotten it to work fine at the moment, but run into problems when I need to create multiple instances of separate threads of this progress bar. I think that this particular progress bar control is using a customized Timer instead of TTimer. Hence causing drawing problems once a second thread is opened with the same control. As for the borland VCL controls they work fine in these threads, no problems at all. "danzer" <.> wrote in message news:48567d47$1@newsgroups.borland.com... > James wrote: >> I would, except that the application that uses this thread form in not a >> C++ Builder application. In fact, it does not have its own support for >> multi-thread, however it does allow dll calls. >> >> Hence, I decided to wrap up a form object into a thread and place that >> into a dll. Then they can create an instance and the form runs. The >> reason I need this is because in their main application they may be >> executing a lengthy database query. I wanted to provide a progress bar >> that shows that the application has not hung, but is retrieving data. >> They also want to use this when they download files, to indicate things >> are going well. >> > > Have you considered having the thread do the "length database query" and > posting status messages to the main application? I have used this method > and it works quite well.
Re: VCL Form inside TThread->Execute
Author: Remy Lebeau (TeamB)
Date: Mon, 16 Jun 2008 16:47
Date: Mon, 16 Jun 2008 16:47
17 lines
1440 bytes
1440 bytes
"James L. Williams" <Jim_L_Williams@hotmail.com> wrote in message news:4853e32c$1@newsgroups.borland.com... > I would like to create a form that exists inside a Thread. That is not safe to do. Do it the other way around - create a TForm and have it run in the main thread normally and have a TThread inside of it. > I want this so that the forms graphics updates are handled inside of a > thread. That will not work correctly. VCL UI updates need to be done in the main 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