以下是一个多线程程序:
 unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    StartGetColor: TButton;
    StopGetColor: TButton;
    ShowColorLabel: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure StartGetColorClick(Sender: TObject);
    procedure StopGetColorClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
  published
    procedure ThreadOnTerminate(Sender: TObject);
    { Public declarations }
  end;var
  Form1: TForm1;
  IsViewThreadRun:Boolean;
implementation
uses Unit2;
{$R *.dfm}
var
  ViewColorThread:TViewColorThread;procedure TForm1.FormCreate(Sender: TObject);
begin
 ViewColorThread:= TViewColorThread.Create;
 StartGetColor.Enabled:=True;
 StopGetColor.Enabled:=False;
 //ViewColorThread.OnTerminate:=Form1.ThreadOnTerminate;
end;procedure TForm1.StartGetColorClick(Sender: TObject);
begin
  StartGetColor.Enabled:=not StartGetColor.Enabled;
  StopGetColor.Enabled:=not StopGetColor.Enabled;
  ViewColorThread.Resume;
end;procedure TForm1.StopGetColorClick(Sender: TObject);
begin
 StartGetColor.Enabled:=not StartGetColor.Enabled;
 StopGetColor.Enabled:=not StopGetColor.Enabled;
 ViewColorThread.Suspend;
end;procedure TForm1.ThreadOnTerminate(Sender:TObject);
begin
 Beep;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 ViewColorThread.Terminate;
end;end.
//////////////////////////////////////////////////////////////////////////
unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Unit1;type
  TViewColorThread = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
   // Procedure OnTerminate;
    procedure show;
  public
    constructor Create;
  end;implementation
var
 GotColor:Integer;
{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TViewColorThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }{ TViewColorThread }
constructor TViewColorThread.Create;
begin
 inherited Create(True);
 //TViewColorThread.OnTerminate:=ThreadOnTerminate;
end;procedure TViewColorThread.Execute;
var
 CursorPoint:TPoint;
 
 ScrDC:HDC;
begin
   FreeOnTerminate:=True;
   while true do
    begin
     sleep(0);
     Synchronize(Show);
     ScrDC:=GetDC(0);
     GetCursorPos(CursorPoint);
     GotColor:=GetPixel(ScrDC,
                        CursorPoint.x,
                        CursorPoint.y
                        );
     ReleaseDC(0,ScrDC);
    end;
 { Place thread code here }
end;procedure TViewColorThread.show;
begin
  Form1.ShowColorLabel.Caption:=IntToStr(GotColor);
end;end.有谁可以帮忙调试一下这个程序??为什么程序在切换线程的过程中以及程序窗口关闭时会不定期的锁死?