type
TQueryThread=class(TThread)
private
FHandle:HWND;
FHasResult:Boolean;
FQuery:TAdoQuery;
procedure QueryExecute;
procedure QueryOpen;
protected
procedure Execute;override;
public
constructor Create(AHandle:HWND; AdoQuery:TAdoQuery; HasResult:Boolean);
end;
implementation
constructor TQueryThread.Create(AHandle:HWND;AdoQuery: TAdoQuery; HasResult: Boolean);
begin
inherited Create(True);
FreeOnTerminate:=True;
FHandle:=AHandle;
FQuery:=AdoQuery;
FHasResult:=HasResult;
Resume;
end;
procedure TQueryThread.Execute;
begin
if FHasResult then
QueryOpen
else
QueryExecute;
end;
procedure TQueryThread.QueryExecute;
begin
try
FQuery.ExecSQL;
PostMessage(FHandle, WM_ThreadDone, Self.ThreadID,0);
except
on E:Exception do
PostMessage(FHandle,WM_ThreadDone, Self.ThreadID,MaxInt);
end;
end;
procedure TQueryThread.QueryOpen;
begin
try
FQuery.Open;
PostMessage(FHandle, WM_ThreadDone, Self.ThreadID,0);
except
on E:Exception do
PostMessage(FHandle,WM_ThreadDone, Self.ThreadID,MaxInt);
end;
end;
觉得这样子很好