Board index » cppbuilder » thead is still valid?

thead is still valid?


2003-07-28 06:52:48 PM
cppbuilder77
Hi,
how do I check, whether a pointer to a thead is still valid?
thread = new TMyThread(false);
thread->FreeOnTerminate = true;
...
the thread terminates by itself
...
thread->Terminate() ;
If the thread is terminated and freed before, I get an AccessViolation.
Thanks,
Andreas
 
 

Re:thead is still valid?

You can add OnDestroy event to your thread object, and you can register your
procedure as OnDestroy event. then when the thread object destroys self, you
will be informed by OnDestroy event...
exm:
////////////////////////////////////////////////////////////////////
class TMy : public TObject
{
protected:
TNotifyEvent FOnDestroy;
public:
__fastcall TMy();
__fastcall ~TMy();
__property TNotifyEvent OnDestroy = {read=FOnDestroy ,
write=FOnDestroy};
}
////////////////////////////////////////////////////////////////////
__fastcall TMy::TMy()
{
FOnDestroy=NULL;
}
////////////////////////////////////////////////////////////////////
__fastcall TMy::~TMy()
{
if (FOnDestroy!=NULL) FOnDestroy(this);
}
////////////////////////////////////////////////////////////////////
{
TMy *Obj=new TMy();
Obj->OnDestroy=...
delete Obj;
}
--
___________________________________
Eyyub Volkan Çektimur
Proya Software & Trade Inc.
Head of Core Development Department
"Andreas Greuer" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

how do I check, whether a pointer to a thead is still valid?

thread = new TMyThread(false);
thread->FreeOnTerminate = true;
...
the thread terminates by itself
...
thread->Terminate() ;
If the thread is terminated and freed before, I get an AccessViolation.

Thanks,
Andreas
 

Re:thead is still valid?

"Eyyub Volkan Çektimur" < XXXX@XXXXX.COM >wrote in message
Quote
You can add OnDestroy event to your thread object, and
you can register your procedure as OnDestroy event. then
when the thread object destroys self, you will be informed
by OnDestroy event...
TThread already has an OnTerminate event for that.
Gambit
 

{smallsort}

Re:thead is still valid?

Thank you,
Andreas