Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Why doesn't my ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 3724 of 3852
Post > Topic >>

Why doesn't my thread terminate?

by Prodigal Son <prodigal.son@[EMAIL PROTECTED] > May 2, 2008 at 03:42 PM

Hi everybody,

I'm trying to learn a thing or two about threads in Delphi, so I'm 
currently messing around with some examples and trying to create a few 
simple examples myself.

My current situation is the following: I have a form which has a button, 
and an editbox. I'd like to start a thread, and update the editbox at 
fixed intervals, from within the thread. But before I even got to that 
part, something strange happened.

Here are a few procedures from my unit:

-- Here I declare the thread, and start it
procedure TMainForm.Button9Click(Sender: TObject);
var
  thread : TMessageThread;
begin
  thread := TMessageThread.Create(true);
  thread.FreeOnTerminate := True;
  thread.OnTerminate := TMessageThreadTerminate;
  thread.Execute;
end;

-- After the thread has terminated, it should say so
procedure TMainForm.TMessageThreadTerminate(Sender: TObject);
begin
  ShowMessage('Terminated');
end;

-- Override for the execute procedure.
procedure TMessageThread.Execute;
var
  i: Integer;
begin
  ShowMessage('Start');
  for i := 0 to 1000 do
  begin
    Application.ProcessMessages;
  end;
  ShowMessage('Stop');
  Terminate;
end;

Now, as soon as I click the button, a messagebox pops up (Start), 
followed by the stop messagebox a few instants later on. But I never get 
the "terminated" message!

This, I don't understand - I've specified the correct procedure (afaikt), 
and I've also tried to do a "DoTerminate" instead of a "Terminate", but 
to no avail.

Can anybody please explain to me what's going on?

Thank you very much!

PS.
 




 5 Posts in Topic:
Why doesn't my thread terminate?
Prodigal Son <prodigal  2008-05-02 15:42:53 
uRe: Why doesn't my thread terminate?
"Skybuck Flying"  2008-05-02 20:52:26 
Re: uRe: Why doesn't my thread terminate?
Prodigal Son <prodigal  2008-05-05 21:27:59 
Re: Why doesn't my thread terminate?
Rob Kennedy <me3@[EMAI  2008-05-02 23:06:03 
Re: Why doesn't my thread terminate?
Prodigal Son <prodigal  2008-05-05 21:37:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:26:54 CDT 2008.