楼上的太不负责了,楼主都说让给个例子了。<br>{线程类。。。<br>单元名称:unDelRecord<br>程 序 员:trm 2008/07/11<br>单元描述:用于删除指定表中的一些无用的数据,并将表中有用的数据再读回来<br>修改历程:<br>}<br>unit unDelRecord;<br><br>interface<br><br>uses ADODB, DB, SysUtils, Classes, Messages, Windows, Forms;<br><br>Type<br> TDelRecord = class(TThread)<br> private<br> procedure _DeleteRecordFromCLTJ(DataSet: TADOQuery; aDayAgo: Integer);<br> public<br> FHandle: THandle;<br> FADOQuery: TADOQuery;<br> FDayAgo: Integer;<br> FExecuteOver: Boolean;<br> procedure Execute;override;<br> constructor Create(CreateSuspended: Boolean; aHandle: THandle);<br> protected<br><br> end;<br><br>implementation<br><br>uses Main;<br><br>{ TDelRecord }<br><br>constructor TDelRecord.Create(CreateSuspended: Boolean; aHandle: THandle);<br>begin<br> inherited Create(CreateSuspended);<br> Fhandle := aHandle;<br>end;<br><br>procedure TDelRecord.Execute;<br>begin<br> inherited;<br> FExecuteOver := False;<br> FreeOnTerminate := True;<br> Application.ProcessMessages; <br> _DeleteRecordFromCLTJ(FADOQuery,FDayAgo);<br> FExecuteOver := True; <br>end;<br><br>procedure TDelRecord._DeleteRecordFromCLTJ(DataSet: TADOQuery; aDayAgo: Integer);<br>var<br> sqlStr: String;<br>begin<br> sqlStr := 'SELECT * into #TEMPTABLE FROM CLTJ WHERE TGSJ > GETDATE() - ' + IntToStr(aDayAgo) +';' +<br> 'truncate table CLTJ;' +<br> 'insert into CLTJ(HPHM, HPZL, HPYS, TGSJ, TGDD, FXJG, CLTP0, CLTP1) ' +<br> 'select HPHM, HPZL, HPYS, TGSJ, TGDD, FXJG, CLTP0, CLTP1 from #TEMPTABLE;' +<br> 'drop table #TEMPTABLE';<br> sqlstr := 'Begin Tran ' + sqlStr;<br> sqlStr := sqlStr + ' if @@error=0 Commit Tran else RollBack';<br><br> with DataSet do<br> begin<br> Close;<br> SQL.Clear;<br> SQL.Text := sqlStr;<br> ExecSQL;<br> end;<br>end;<br><br>end.<br><br>//////<br>//下面是调用线程的窗体<br>//////<br>var<br> Frm_Main: TFrm_Main;<br>{$message warn '定义线程'}<br> td: TDelRecord;<br>implementation<br>{$R *.dfm}<br>procedure TFrm_Main.FormCreate(Sender: TObject);<br>begin<br> {$message warn '构造线程对象'}<br> td := TDelRecord.Create(True, Self.Handle);<br>end;<br>procedure TFrm_Main.FormDestroy(Sender: TObject);<br>begin<br> {$message warn '释放线程'}<br> td.Destroy;<br>end;<br><br>procedure TFrm_Main.N12Click(Sender: TObject);//按钮事件<br>begin<br> {$message warn '唤醒线程'}<br> ClearDBTimer.Enabled := True;//一个Timer控件<br> td.Resume; <br>end;<br><br>procedure TFrm_Main.ClearDBTimerTimer(Sender: TObject);<br>begin//Timer.Intervalue := 100;<br> {$message warn '在Timer中写关于进度条的事件'}<br> Application.ProcessMessages;<br> ProgressBar1.Min := 0;<br> ProgressBar1.Max := 10000;<br> ProgressBar1.Step := 1;<br> while ProgressBar1.Position <> ProgressBar1.Max do<br> begin<br> ProgressBar1.StepIt;<br> if ProgressBar1.Position = ProgressBar1.Max then<br> ProgressBar1.Position := 0;<br> Application.ProcessMessages;<br> if not ClearDBTimer.Enabled then<br> Exit;<br> if td.FExecuteOver then<br> begin<br> ProgressBar1.Position := 0;<br> Exit;<br> end;<br> end;<br>end;<br>end.<br>//差不多了。。。