这样做可以释放线程对象吗?
unit SnapThread;
interface
uses
Classes, Windows;
type
TSnapThread = class(TThread)
private
{ Private declarations }
m_hcg: LongWord;
m_hWnd: LongWord;
m_DC: LongWord;
m_x,m_y,m_width,m_height:LongWord;
m_nBufSize:LongWord;
m_Buf:Pchar;
protected
procedure Execute; override;
public
constructor Create(hcg:LongWord; hwnd:LongWord;
x,y,width,height:LongWord);
procedure Free;//这样声明可以吗?
end;
implementation
constructor TSnapThread.Create(hcg, hWnd: LongWord; x, y, width, height: LongWord);
begin
m_hcg := hcg;
m_hWnd := hWnd;
m_DC:= GetDC(m_hWnd);
m_x:=x;
m_y:=y;
m_width :=width;
m_height :=height;
m_nBufSize := m_width*m_height*3;
GetMem(m_Buf, m_nBufSize);
self.FreeOnTerminate:=False;
inherited Create(True);
end;
procedure TSnapThread.Free;
begin
ReleaseDC(m_hWnd, m_DC);
FreeMem(m_Buf, m_nBufSize);
inherited Free;
end;
然后再主程序中这样建立和释放,可以吗?
var
m_SnapThread :TSnapThread;
begin
m_SnapThread := TSnapThread.Create(m_hcg, self.Handle, 4, 4, 100, 100);
。。。。。
。。。。。
m_SnapThread.Free;
end;