Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thread - OnTerminate Event

Status
Not open for further replies.

gp4

Technical User
Sep 27, 2002
30
AU
I have created a thread to execute in my application but I'm not sure where you would Declare the OnTerminate event handler.
Any ideas?

N.B my thread code is contained in unit2.pas and my main code is in unit1.pas for example.

 
Hi.

Try this snippet...
Code:
type
  TMyThread = class(TThread)
  private
    procedure ThreadDone(Sender: TObject);
  public
    constructor Create(CreateSuspended: Boolean);
  end;

implementation

constructor TMyThread.Create(CreateSuspended: Boolean);
begin
  OnTerminate := ThreadDone;
end;

procedure TMyThread.ThreadDone(Sender: TObject);
begin
  // Do you stuff here
end;

//Nordlund
 
Hi Nordlund,
Thanks again for your feedback.
I tried the above code but I get an exception when I create the thread by calling from the main application:

Tmythread.Create(false);

I get the error:

'Thread error: The handle is invalid (6).'

Any ideas what could be wrong?

Thanks
 
Hi,

I suppose you do it this way??

Code:
var mythread : tmythread;

begin
...
 mythread:=tmythread.create(false);
...
end;

anyway, if you want to learn more about threads, I suggest you read this site :
it gives great insight about threads in a windows environment.

cheers


--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top