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;
http://blog.csdn.net/warrially/article/details/7887700