我需要在查询执行之前显示一个弹出窗口,显示执行sql查询时经过的时间,并在查询结束时关闭该窗口.
其实我做的是这样的
var
frm : tFrmPopupElapsed;
// this form has a TTimer and a TLabel to show the elapsed time
// but the label is not updated, I tried using update and refresh
// but nothing happens
begin
frm := tFrmPopupElapsed.Create(nil);
try
frm.Init; // this procedure enables the timer
frm.Show();
ExecuteMyVeryLongQuery();
finally
frm.Close;
end;
end;
Run Code Online (Sandbox Code Playgroud)
如何更新标签以显示查询执行时所用的时间?使用计时器?还是线程?
您需要异步运行查询,以便您同时更新表单。
无需亲自处理线程的最简单方法是使用 Andreas Hausladen 的AsynCalls 库。
您还可以查看Primoz Gabrijelcic 的OmniThread Library。