Thread View: comp.lang.pascal.delphi.components.misc
4 messages
4 total messages
Started by Sterling Bates
Fri, 06 Jul 2001 06:38
TForm inside a TThread
Author: Sterling Bates
Date: Fri, 06 Jul 2001 06:38
Date: Fri, 06 Jul 2001 06:38
22 lines
1752 bytes
1752 bytes
I'm use several TThreads to spawn instances of the same form multiple times;
ie:
procedure TSpawnFormThread.Execute;
begin
FreeOnTerminate := true;
with TMyForm.Create(nil) do
begin
ShowModal;
Release;
end;
end;
This tends to create interesting errors (window handle no longer valid) on
the Release of the form, and the message "Canvas does not allow drawing"
when activating a form (this primarly caused, it seems, by TRichEdit).
Another poster mentioned that only the main VCL thread properly handles
forms, but need to know if there's an elegant way to work with this.
Note: I *do* need to pop up multiple instances of the same form -- I'm open
to suggestions on other ideas.
Re: TForm inside a TThread
Author: Bruce Roberts
Date: Fri, 06 Jul 2001 08:03
Date: Fri, 06 Jul 2001 08:03
25 lines
2189 bytes
2189 bytes
"Sterling Bates" <noone@nowhere.com> wrote in message news:T1d17.12112$E93.2145422@news1.telusplanet.net... > I'm use several TThreads to spawn instances of the same form multiple times; > This tends to create interesting errors (window handle no longer valid) on > the Release of the form, and the message "Canvas does not allow drawing" > when activating a form (this primarly caused, it seems, by TRichEdit). > > Another poster mentioned that only the main VCL thread properly handles > forms, but need to know if there's an elegant way to work with this. > > Note: I *do* need to pop up multiple instances of the same form -- I'm open > to suggestions on other ideas. The VCL is not thread safe. What you are trying to do will simply not work. But you don't need threads to do what you want. Instead set Action to caFree in the form's OnClose and use the following code like the following (shows 2 copies of the same form) tMyForm.Create (Application).Show; tMyForm.Create (Application).Show;
Re: TForm inside a TThread
Author: Sundial Services
Date: Fri, 06 Jul 2001 17:06
Date: Fri, 06 Jul 2001 17:06
47 lines
3029 bytes
3029 bytes
An application can have as many windows open as it wishes; including, if
you like, multiple copies of the same form. (You simply must be sure
that you keep each TForm object separate from the others, e.g. in a
TList. You can't use Delphi's standard trick of creating a global
variable to hold it.)
Intrinsically, a form .. any Windows window .. is dependent upon the
Windows software to draw and maintain it, and this occurs through the
use of Windows messages. Only one thread (the main thread) should be
having anything to do with Windows messages. It can, however, support
any number of windows at the same time. (All the messages for all the
windows flow through it.)
>Sterling Bates wrote:
>
> I'm use several TThreads to spawn instances of the same form multiple times;
> ie:
>
> procedure TSpawnFormThread.Execute;
> begin
> FreeOnTerminate := true;
> with TMyForm.Create(nil) do
> begin
> ShowModal;
> Release;
> end;
> end;
>
> This tends to create interesting errors (window handle no longer valid) on
> the Release of the form, and the message "Canvas does not allow drawing"
> when activating a form (this primarly caused, it seems, by TRichEdit).
>
> Another poster mentioned that only the main VCL thread properly handles
> forms, but need to know if there's an elegant way to work with this.
>
> Note: I *do* need to pop up multiple instances of the same form -- I'm open
> to suggestions on other ideas.
------------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:info@sundialservices.com (PGP public key available.)
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R): "Click click, it's fixed!" {tm}
> http://www.sundialservices.com/products/chimneysweep
Re: TForm inside a TThread
Author: Sterling Bates
Date: Fri, 06 Jul 2001 17:18
Date: Fri, 06 Jul 2001 17:18
55 lines
3260 bytes
3260 bytes
The TList is exactly how I went about it. Thanks to you and Bruce for your
help.
"Sundial Services" <info_NS1@sundialservices.com> wrote in message
news:3B45F003.2FA5@sundialservices.com...
> An application can have as many windows open as it wishes; including, if
> you like, multiple copies of the same form. (You simply must be sure
> that you keep each TForm object separate from the others, e.g. in a
> TList. You can't use Delphi's standard trick of creating a global
> variable to hold it.)
>
> Intrinsically, a form .. any Windows window .. is dependent upon the
> Windows software to draw and maintain it, and this occurs through the
> use of Windows messages. Only one thread (the main thread) should be
> having anything to do with Windows messages. It can, however, support
> any number of windows at the same time. (All the messages for all the
> windows flow through it.)
>
>
>
>
> >Sterling Bates wrote:
> >
> > I'm use several TThreads to spawn instances of the same form multiple
times;
> > ie:
> >
> > procedure TSpawnFormThread.Execute;
> > begin
> > FreeOnTerminate := true;
> > with TMyForm.Create(nil) do
> > begin
> > ShowModal;
> > Release;
> > end;
> > end;
> >
> > This tends to create interesting errors (window handle no longer valid)
on
> > the Release of the form, and the message "Canvas does not allow drawing"
> > when activating a form (this primarly caused, it seems, by TRichEdit).
> >
> > Another poster mentioned that only the main VCL thread properly handles
> > forms, but need to know if there's an elegant way to work with this.
> >
> > Note: I *do* need to pop up multiple instances of the same form -- I'm
open
> > to suggestions on other ideas.
>
> ------------------------------------------------------------------
> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
> mailto:info@sundialservices.com (PGP public key available.)
> > Fast(!), automatic table-repair with two clicks of the mouse!
> > ChimneySweep(R): "Click click, it's fixed!" {tm}
> > http://www.sundialservices.com/products/chimneysweep
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