纪录每个线程的Handle,在这里你用了TThread类,那么你可以记录NewThread,如果需要结束线程,那么TThread.Terminated设置为True。

解决方案 »

  1.   

    你可以建一个NewThread的全局数组,然后把每次创建的线程对象依次放进去,
    你只要维护好这个数组就行了,自然想停哪个就停哪个
      

  2.   

    你访问了主线程(Application.Form)的东西,注意同步
    用TList来管理你的线程:constructor TForm1.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FList  := TList.Create;  
    end;
    destructor TForm1.Destroy;
    var
      I: Integer;
    begin
      for I := 0 to FList.Count - 1 do
        FreeMem(FList[I]);
      Flist.Free;
      inherited Destroy; 
    end;procedure TForm1.AddThread;
    var
      Thread: TMyThread;
    begin
      Thread := TMyThread.Create(Edit1, 1000);
      Flist.Add(Thread);  
    end;procedure TForm1.DeleteThread(Index: Integer);
    begin
      with TMyThread(FList[Index]) do
      begin
        Terminate;
        //FreeOnTerminated := True;不用再去Free,它自动会Free,else 这里调用Free
      end;
      Flist.Delete(Index);  
    end;访问主线程的数据,需要同步控制,在次线程中用Synchroze(ProcMethod);
    或在主线程中用TThreadList, SyncObjs.TCriticalSection控制。