Board index » cppbuilder » Re: TThread & VK_ESCAPE hangs the form...

Re: TThread & VK_ESCAPE hangs the form...

2005-12-28 07:00:01 PM
At 10:50:07, 28.12.2005, Remy Lebeau (TeamB) wrote:

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message


No. 'this' is being passed to a TThread constructor. TThread has no
Owner mechanism since it is not a TComponent descendant.
Hmmm... I should read the full thread back, next time. I was not aware it
was a thread (yes, the name should have told me). Thanks for the
correction. <g>
Rudy.Velthuis {TeamB}
"If you gaze long into an abyss, the abyss will gaze back into you."
- Friedrich Nietzsche (1844-1900)

Re:Re: TThread & VK_ESCAPE hangs the form...

If you look more closely at the code I gave you, I am using the
thread's FreeOnTerminate property. The thread automatically
frees its memory when it finishes running.
Thank you for the explanation. Yes I saw the FreeOnTerminate
but didn't knew that it's all that is needed to free it.
Best regards,
Vladimir Stefanovic

Re:Re: TThread & VK_ESCAPE hangs the form...

I guess everyone has their preferred use of TThread, my preference is to
create the thread suspended, and start it after the constructor returns, and
not to have the thread clean up, so the owner calls the TerminateAndWait,
and when that returns delete it.
Did this chain highlight a problem in using TerminateAndWait if the thread
uses Synchronise? Or does the fact that I don't have the thread cleaning up
bypass this problem?
I also haven't use synchronise recently, I have used a queuing system to
pass data back from the thread to the form. At this moment in time the
mechanism works for me, but I suppose one day I will implement something
that doesn't lend itself to this.
__fastcall CTask::CTask( char * name_string,
int identity,
int priority ) : TThread(true)
// make sure thread is deleted by owner
FreeOnTerminate = false;
void __fastcall
// some code from the form to create and run thread, then, terminate and
delete thread
instance = new CTask( "CScheduler",-1,-1 );
delete instance;
instance = NULL;
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message

"Steve Aletto" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


Yes, really: