给你个Demo,但是你的存储过程要是在主线程里面执行的话估计也难免影响到子线程的执行,建议在子线程中执行存储过程,这样主界面没有死机现象。<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ComCtrls, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> ProgressBar1: TProgressBar;<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> type<br> TTestThread = class(TThread)<br> private<br> Fpb: TProgressBar;<br> iPos: integer;<br> procedure DoWhatVCLAction;<br> public<br> procedure Execute; override;<br> constructor Create(pb: TProgressBar);<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>constructor TTestThread.Create(pb: TProgressBar);<br>begin<br> Fpb:= pb;<br> iPos:= pb.Position;<br> FreeOnTerminate:= true;<br> inherited Create(False);<br>end;<br><br>procedure TTestThread.DoWhatVCLAction;<br>begin<br> Fpb.Position:= iPos;<br>end;<br><br>procedure TTestThread.Execute;<br>begin<br> while iPos < 100 do<br> begin<br> Inc(iPos);<br> //访问 VCL 的行为一定在 Synchronize 里!<br> synchronize(DoWhatVCLAction);<br> if Terminated then exit;<br> Sleep(20);<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> N: integer;<br>begin<br> TTestThread.Create(ProgressBar1);<br> for N:= 0 to 100000 do<br> begin<br> Application.ProcessMessages;<br> end;<br>end;<br><br>end.