我无法让这个线程终止。我在哪里犯了错误?
type
TThumbnailThread = class(TThread)
public
procedure Execute; override;
procedure CreateContactSheets;
end;
procedure TThumbnailThread.Execute;
begin
while not Terminated do
begin
CreateContactSheets;
Synchronize(CreateContactSheets);
end;
end;
procedure TThumbnailThread.CreateContactSheets;
const
iColumns: integer = 6;
iRows: integer = 6;
iHorzontalSpace: integer = 0;
iVerticalSpace: integer = 0;
iHorzontalMargin: integer = 0;
iVerticalMargin: integer = 0;
iDrawBox: boolean = true;
iDrawText: boolean = True;
iDrawShadow: boolean = True;
iBackgroundColor: TColor = clWhite;
iBoxColor: TColor = clBlack;
iPageNo: Integer = -1;
begin
Form1.ImageEnMView1.MIO.PrintImagesToFile(Form1.AThumbnailFilename, 80, Screen.Width,
Screen.Height, iColumns, Rows, iHorzontalSpace, iVerticalSpace,
Form1.PrintSelected1.Checked, iHorzontalMargin, iVerticalMargin, iDrawBox, iDrawText,
iDrawShadow, iBackgroundColor, iBoxColor, iPageNo);
end;
procedure TForm1.PrintToFile1Click(Sender: TObject);
begin
if SavePictureDialog1.Execute then
begin
if SavePictureDialog1.FileName <> '' then
begin
Screen.Cursor := crHourGlass;
try
iFilename := SavePictureDialog1.FileName;
{ If one thread have been started already, we don't start another. }
if ThumbnailThread <> nil then
raise Exception.Create('One thread has already been started!');
AThumbnailFilename := iFilename;
ThumbnailThread := TThumbnailThread.Create(false);
ThumbnailThread.OnTerminate := TerminateTheThread;
finally
Screen.Cursor := crDefault;
end;
end;
end;
end;
procedure TForm1.Abort1Click(Sender: TObject);
begin
ThumbnailThread.Terminate;
ProgressBar1.Position := 0;
Screen.Cursor := crDefault;
end;
procedure TForm1.TerminateTheThread;
begin
Form1.ImageEnMView1.MIO.Aborting := True;
end;