TTestThread = class(TThread)
.........省略
Var
T1:TTestThread;
.........省略
.........省略
procedure zantingxc();
Begin
    SuspendThread(T1); //挂起线程           这样会提示Incompatible types 'cardinal'and 'TTestThread'
End;换种方式:
procedure zantingxc();
Begin
    T1.Suspend;   //挂起线程     这样F9编译可以通过,当调用这个过程时会弹出错误。
End;//****************************请教详细正确的在线程运行时暂停和继续线程的方法******************************请教详细正确的在线程运行时暂停和继续线程的方法,在线等,或者加QQ19六97肆539,谢谢分散完了,请求大家帮帮忙

解决方案 »

  1.   

    报错?可能你线程已经结束了SuspendThread(T1.handle)
      

  2.   

    线程内:
    type
      TTestThread=class(TThread)
      ...
      public
        constructor Create(CreateSuspended:Boolean);
      ...constructor TTestThread.Create(CreateSuspended:Boolean);
    begin 
      FreeOnTerminate:=true;
      inherited Create(CreateSuspended);
    end;procedure TTestThread.Execute; 
    begin 
      if not Terminated then
        ...
    end;窗体中:
    uses ...
    var 
      h:TTestThread;  以下用4个button,每个1句代码
      h:=TRearThread.Create(true); //创建,有其它参数就传参数
      h.Resume;      //激活
      h.Suspend;     //挂起
      h.Terminate;   //结束
      

  3.   

    不建议用 suspend 和 resume来操作线程,在新版本的Delphi中,这两个方法都废弃掉了。
    你可用 TEvent,TMutex等对线程进行控制。
    可以看万一的博客,上面有多线程入门。
      

  4.   

    我执行的线程要调用很多的函数,要是每个函数都加一句“if not Terminated then”来判断是不是太麻烦了呢
      

  5.   

    已经解决,把线程类改成API就可以了,谢谢