unit Umythread;
interface
uses
Classes,db,StdCtrls,SysUtils,udatamodule1,Graphics,Math,Buttons;
//自定义线程,对通信接受的数据进行处理
type
tmythread = class(TThread)
proceduredo
comm;
//数据处理过程
private{ Private declarations }
protected
procedure Execute;
override;
public
constructor Create (Suspended:Boolean);
end;
implementation
constructor tmythread.Create(Suspended:Boolean);
begin
inherited Create(Suspended);
FreeOnTerminate:=true;
end;
procedure tmythread.Execute;
//线程执行过程
begin
//1
while not Terminated do
begin
do
comm;
sleep(5);
end;
//1
end;
procedure tmythread.docomm;
begin
//处理
end;
end;
end.
再在主线程中声明线程对象
var
mythread:tmythread;
然后执行
mythread:=tmythread.create(false);
最后不用时释放
mythread.Terminate;