Hi all, I have made a single thread, to generate random
words for me ... But I have a problem with the thread.
When I tell it to terminate it keeps generating words
for me.
Even though Delphi says that my thread is terminated, it
just keeps going.
Here is my code:
I hope you guys can tell me why nothing happens when I do
this:
Thanks in advance for your help,
BobbaFet
Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
words for me ... But I have a problem with the thread.
When I tell it to terminate it keeps generating words
for me.
Even though Delphi says that my thread is terminated, it
just keeps going.
Here is my code:
Code:
type
TGeneratorThread = class(TThread)
protected
Letters: array[0..25] of PChar;
procedure FillArray;
procedure Execute; override;
end;
... bla bla bla ...
procedure TGeneratorThread.FillArray;
begin
Letters[0] := 'A';
Letters[1] := 'B';
Letters[2] := 'C';
Letters[3] := 'D';
Letters[4] := 'E';
Letters[5] := 'F';
Letters[6] := 'G';
Letters[7] := 'H';
Letters[8] := 'I';
Letters[9] := 'J';
Letters[10] := 'K';
Letters[11] := 'L';
Letters[12] := 'M';
Letters[13] := 'N';
Letters[14] := 'O';
Letters[15] := 'P';
Letters[16] := 'Q';
Letters[17] := 'R';
Letters[18] := 'S';
Letters[19] := 'T';
Letters[20] := 'U';
Letters[21] := 'V';
Letters[22] := 'W';
Letters[23] := 'X';
Letters[24] := 'Y';
Letters[25] := 'Z';
end;
procedure TGeneratorThread.Execute;
var i, i2, LettersInWord, NumOfWords: Integer;
MyWord, MyPrevWord: String;
begin
Synchronize(FillArray);
Form1.StatusBar1.Panels[0].Text := '';
Form1.StatusBar1.Panels[1].Text := '';
Form1.StatusBar1.Panels[2].Text := '';
Form1.StatusBar1.Panels[3].Text := '';
i := 0;
LettersInWord := StrToInt(Form1.Edit2.Text);
NumOfWords := StrToInt(Form1.Edit1.Text);
Form1.ProgressBar1.Max := NumOfWords;
if Form1.CheckBox2.Checked then
Form1.RichEdit1.Clear;
Form1.RichEdit1.Refresh;
MyPrevWord := '';
if MessageDlg('Start generating the words ???',mtConfirmation,[mbNo,mbYes],0) = mrYes then
while i < NumOfWords do
begin
i2 := 0;
Randomize;
if not Form1.CheckBox1.Checked then
MyWord := '';
while i2 < LettersInWord do
begin
i2 := i2 + 1;
MyWord := MyWord + String(Letters[Random(25)]);
end;
if MyPrevWord <> MyWord then
begin
Form1.RichEdit1.Lines.Add(MyWord);
i := i + 1;
Form1.ProgressBar1.Position := i;
MyPrevWord := MyWord;
Form1.StatusBar1.Panels[0].Text := IntToStr(i) + ' of the ordered ' + IntToStr(NumOfWords) + ' words';
Form1.StatusBar1.Panels[1].Text := 'Generating ' + IntToStr(LettersInWord) + ' letter words';
Form1.StatusBar1.Refresh;
end;
end;
Form1.ProgressBar1.Position := 0;
end;
I hope you guys can tell me why nothing happens when I do
this:
Code:
procedure button1click(sender: tobject);
var GenThr: TGeneratorThread;
begin
GenThr.Terminate;
end;
Thanks in advance for your help,
BobbaFet
Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com