Delphi线程类 DIY

Delphi 封装了一个很强大的线程类 TThread, 


我们也自己动手制作一个简单的线程类


首先Type一个类

type
  TwwThread = class
    constructor Create; overload;
    destructor Destroy; override;
  private
    m_hThread: THandle;		//线程
    m_ThreadID : TThreadID;
  public
    procedure Execute;
  end;



function wwThreadProc(Thread: TwwThread): Integer;
begin
  Thread.Execute(); //
end;
constructor TwwThread.Create;
begin
  m_hThread := CreateThread(nil, 0, @wwThreadProc, Pointer(Self), 0, m_ThreadID); { 这里的重点是第四个参数, 把类指针作为参数传进去,这样就可以执行类里面的方法啦}
end;
destructor TwwThread.Destroy;
begin
  inherited;
end;
procedure TwwThread.Execute;
begin
  // 这里写上代码
end;

声明一下:

var
  myThread : TwwThread;


开始~
myThread := TwwThread.Create;


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值