我做了一个接收网络数据的过程recarm,我想用线程时时监听网络是否有数据传来,请问该如何做

解决方案 »

  1.   

    unit Unit2;interfaceuses
      Classes;type
      test = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation{ 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 test.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ test }procedure test.Execute;
    begin
      { Place thread code here }
    end;end.
      

  2.   

    unit Unit2;interfaceuses
      Classes;type
      test = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation{ 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 test.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ test }procedure test.Execute;
    begin
      while (not Terminated) do
      begin
        //--你的代码
      end;
    end;end.
      

  3.   

    调用的时候create就可以了
    var
      Atest: test; 
    begin
      Atest := Test.create(false);
    end;