请教高手一个执行大量查询时界面如何不死,分不多了(50分)

  • 主题发起人 主题发起人 zhiyouyigewo
  • 开始时间 开始时间
Z

zhiyouyigewo

Unregistered / Unconfirmed
GUEST, unregistred user!
请教一下,如果我想做这么一个功能,在执行大量查询的时候弹出一个窗口显示程序执行中,在查询完后这个窗口关闭,原来页面的查询结果显示出来,要保证界面不死掉,我知道是用多线程,但是具体到这个功能怎么实现怎么写还请帮忙,本人很久没写DELPHI了,请把代码写完全写清楚一点,谢谢,本人分不多了,如果有要求可以再加,但程序要写好
 
可以在Query的BeforeOpen,AfterOpen事件中来控制
 
同意楼上
 
大哥们,不是吧,就在OPEN前showmodal一个,然后open后把那个CLOSE掉,这样不好吧,你们把代码写出来试试
 
disabledcontrols<br>try<br>finally<br>&nbsp; enabledcontrols<br>end
 
数据量非常大的时候建议分页.支取需要的数据.当用户翻页的时候才取下一页
 
不一定是数据量大,有可能是处理时间长,我的意思就是在处理的时候不叫他的界面死掉,我知道是用多线程,不过我想在用的时候弹出一个提示的界面来,而且不知道怎么写,希望能把所有代码给写的详细一点出来
 
进度条。。。
 
只能在线成中执行,林外加一个定时器显示进度!
 
就是多线程了撒,然后将查询结果不断的显示在界面上,比如pl sql这个工具,当从Oracle数据库上查询几万甚至几十万条数据的时候,就是在不停的显示。
 
老大么,概念我当然知道,我的主题中也说了,不过就是不知道怎么写,也没有例子,麻烦谁写出个完整的代码出来,分我还可以加啊,写出个能实现的例子
 
//简单的线程例子,仅供参考<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;<br><br>type<br>&nbsp; timethread= class(TThread)<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; end;<br><br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; btnPause: TButton;<br>&nbsp; &nbsp; btnResume: TButton;<br>&nbsp; &nbsp; btnKill: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure btnPauseClick(Sender: TObject);<br>&nbsp; &nbsp; procedure btnResumeClick(Sender: TObject);<br>&nbsp; &nbsp; procedure btnKillClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; TIME_THREAD:TIMETHREAD;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure timethread.execute;<br>var<br>&nbsp; go:boolean ;<br>begin<br>&nbsp; go:=true;<br>&nbsp; repeat<br>&nbsp; &nbsp; //这里写你的查询代码<br>&nbsp; &nbsp; //查询结束设置go:=false;<br>&nbsp; until go=false;<br>end;<br>&nbsp;<br>procedure TForm1.btnKillClick(Sender: TObject);<br>begin<br>&nbsp; Time_thread.terminate;<br>end;<br><br>procedure TForm1.btnPauseClick(Sender: TObject);<br>begin<br>&nbsp; Time_thread.suspend;<br>end;<br><br>procedure TForm1.btnResumeClick(Sender: TObject);<br>begin<br>&nbsp; Time_thread.resume;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; time_thread.Terminate;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; time_thread:=timethread.create(false);<br>end;<br><br>end.
 
你注意到query控件,不是adoquery控件没,用它来返回查到的数据量大时它分页显示的,而adoquery是全部显的,所以它慢(感谢觉上,其实不慢,只是处理方式不同而已,),如果一定要用adoquery的话可以用多线程异步查询,但快步查询进度较难做准确,即使做出来也是不准的
 
很感谢大家,简单线程的例子我也有,我是想实现我说的那种功能,就是在我执行的时候去弹出来一个窗口,可以不用显示查询的进程,但是弹出的窗口界面不能死掉,而那边执行完后弹出的窗口给个提示后关闭,就是这种效果,希望谁写出个详细的例子,只要功能实现了,我的分还可以加,谢谢!
 
unit utWaitFlash;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls, StdCtrls, ImgList, dxCntner, dxEditor, dxExEdtr, dxEdLib;<br><br>type<br>&nbsp; TfrmWaitFlash = class(TForm)<br>&nbsp; &nbsp; pnForm: TPanel;<br>&nbsp; &nbsp; Image1: TImage;<br>&nbsp; &nbsp; edt_Mess: TdxMemo;<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br><br>&nbsp; public<br>&nbsp; end;<br><br>var<br>&nbsp; frmWaitFlash: TfrmWaitFlash;<br>&nbsp; Procedure ShowWait(aText: string='');<br>&nbsp; Procedure ClearWait;<br><br>implementation<br><br>{$R *.DFM}<br>Procedure ShowWait(aText: string='');<br>var<br>&nbsp; myMessage: string;<br>begin<br>&nbsp; myMessage := aText;<br>&nbsp; if myMessage='' then myMessage := '系统正在处理数据,请稍等...';<br>&nbsp; if Application.FindComponent('frmWaitFlash') = nil then<br>&nbsp; &nbsp; frmWaitFlash := TfrmWaitFlash.Create(Application);<br>&nbsp; frmWaitFlash.edt_Mess.Text := aText;<br>&nbsp; frmWaitFlash.Show;<br>&nbsp; frmWaitFlash.Refresh;<br>end;<br><br>Procedure ClearWait;<br>begin<br>&nbsp; if Application.FindComponent('frmWaitFlash') &lt;&gt; nil then<br>&nbsp; &nbsp; frmWaitFlash.Free;<br>end;<br><br>procedure TfrmWaitFlash.FormClose(Sender: TObject;<br>&nbsp; var Action: TCloseAction);<br>begin<br>&nbsp; Action := caFree;<br>end;<br><br>end.<br><br>示例:<br>ShowWait('我正在处理,请耐心等待....');<br>{你的查询代码}<br>ClearWait;
 
谢谢各位大哥,不过效果是这样,但多线程要写在哪才能使界面不死掉啊,希望给一个完整的例子
 
Application.ProcessMessages<br><br>让权呀
 
有问的这点时间,自己动一下手吧,大家都说这么多了,别人嚼的饭不香的.
 
楼上的太不负责了,楼主都说让给个例子了。<br>{线程类。。。<br>单元名称:unDelRecord<br>程 序 员:trm &nbsp;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>&nbsp; TDelRecord = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; procedure _DeleteRecordFromCLTJ(DataSet: TADOQuery; aDayAgo: Integer);<br>&nbsp; public<br>&nbsp; &nbsp; FHandle: THandle;<br>&nbsp; &nbsp; FADOQuery: TADOQuery;<br>&nbsp; &nbsp; FDayAgo: Integer;<br>&nbsp; &nbsp; FExecuteOver: Boolean;<br>&nbsp; &nbsp; procedure Execute;override;<br>&nbsp; &nbsp; constructor Create(CreateSuspended: Boolean; aHandle: THandle);<br>&nbsp; protected<br><br>&nbsp; end;<br><br>implementation<br><br>uses Main;<br><br>{ TDelRecord }<br><br>constructor TDelRecord.Create(CreateSuspended: Boolean; aHandle: THandle);<br>begin<br>&nbsp; inherited Create(CreateSuspended);<br>&nbsp; Fhandle := aHandle;<br>end;<br><br>procedure TDelRecord.Execute;<br>begin<br>&nbsp; inherited;<br>&nbsp; FExecuteOver := False;<br>&nbsp; FreeOnTerminate := True;<br>&nbsp; Application.ProcessMessages; &nbsp;<br>&nbsp; _DeleteRecordFromCLTJ(FADOQuery,FDayAgo);<br>&nbsp; FExecuteOver := True; <br>end;<br><br>procedure TDelRecord._DeleteRecordFromCLTJ(DataSet: TADOQuery; aDayAgo: Integer);<br>var<br>&nbsp; sqlStr: String;<br>begin<br>&nbsp; sqlStr := 'SELECT * into #TEMPTABLE FROM CLTJ WHERE TGSJ &gt; GETDATE() - ' + IntToStr(aDayAgo) +';' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'truncate table CLTJ;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'insert into CLTJ(HPHM, HPZL, HPYS, TGSJ, TGDD, FXJG, CLTP0, CLTP1) ' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'select HPHM, HPZL, HPYS, TGSJ, TGDD, FXJG, CLTP0, CLTP1 from #TEMPTABLE;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'drop table #TEMPTABLE';<br>&nbsp; sqlstr := 'Begin Tran ' + sqlStr;<br>&nbsp; sqlStr := sqlStr + ' if @@error=0 Commit Tran else RollBack';<br><br>&nbsp; with DataSet do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; SQL.Text := sqlStr;<br>&nbsp; &nbsp; ExecSQL;<br>&nbsp; end;<br>end;<br><br>end.<br><br>//////<br>//下面是调用线程的窗体<br>//////<br>var<br>&nbsp; Frm_Main: TFrm_Main;<br>{$message warn '定义线程'}<br>&nbsp; td: TDelRecord;<br>implementation<br>{$R *.dfm}<br>procedure TFrm_Main.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;{$message warn '构造线程对象'}<br>&nbsp; td := TDelRecord.Create(True, Self.Handle);<br>end;<br>procedure TFrm_Main.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; &nbsp;{$message warn '释放线程'}<br>&nbsp; td.Destroy;<br>end;<br><br>procedure TFrm_Main.N12Click(Sender: TObject);//按钮事件<br>begin<br>&nbsp; &nbsp;{$message warn '唤醒线程'}<br>&nbsp; ClearDBTimer.Enabled := True;//一个Timer控件<br>&nbsp; td.Resume; &nbsp; <br>end;<br><br>procedure TFrm_Main.ClearDBTimerTimer(Sender: TObject);<br>begin//Timer.Intervalue := 100;<br>&nbsp; {$message warn '在Timer中写关于进度条的事件'}<br>&nbsp; Application.ProcessMessages;<br>&nbsp; ProgressBar1.Min := 0;<br>&nbsp; ProgressBar1.Max := 10000;<br>&nbsp; ProgressBar1.Step := 1;<br>&nbsp; while ProgressBar1.Position &lt;&gt; ProgressBar1.Max do<br>&nbsp; begin<br>&nbsp; &nbsp; ProgressBar1.StepIt;<br>&nbsp; &nbsp; if ProgressBar1.Position = ProgressBar1.Max then<br>&nbsp; &nbsp; &nbsp; ProgressBar1.Position := 0;<br>&nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; &nbsp; if not ClearDBTimer.Enabled &nbsp;then<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; if td.FExecuteOver then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;ProgressBar1.Position := 0;<br>&nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>end.<br>//差不多了。。。
 
后退
顶部