我已经搜索和搜索,但无法找到如何在 Delphi 中获取查询的进度。我找到了 Advantage .NET 数据提供程序的一些信息,但可以使用 Delphi 的一些帮助。
问问题
921 次
1 回答
7
您需要AdsRegisterCallbackFunction方法。这是一个快速示例,用于在为 TAdsTable 创建索引期间显示进度;对于 a 的进展,它的工作方式完全相同TAdsQuery
:
implementation
var
// Holder for reference to progressbar on form, so it can be
// accessed easily from the callback - see below
PB: TProgressBar = nil;
// replacement for Application.ProcessMessages, since we don't have
// access to the Application from the callback either
procedure KeepWindowsAlive;
var
M: TMsg;
begin
if PeekMessage(M, 0, 0, 0, pm_Remove) then
begin
TranslateMessage(M);
DispatchMessage(M);
end;
end;
// The callback function itself - note the stdcall at the end
// This updates the progressbar with the reported percentage of progress
function ProgressCallback(Percent: Word; CallBackID: LongInt): LongInt; stdcall;
begin
if PB <> nil then
PB.Position := Percent;
KeepWindowsAlive;
Result := 0;
end;
// The button click handler. It registers the callback, calls a function
// that creates the index (not shown here), and then unregisters the callback.
//
// As I mentioned above, it works the same way with a TAdsQuery.
// You'd simply assign the SQL, set any params, and register the
// callback the same way. Then, instead of calling my CreateIndexes
// method, you'd Open the query; it will call the progress callback
// periodically, and when the query finishes you just unhook the
// callback as shown here.
procedure TCreateIndexesForm.CreateButtonClick(Sender: TObject);
begin
// Grab a reference to the progress bar into the unit global, so we don't
// need a reference to the form by name in the callback.
PB := Self.ProgressBar1;
// AdsTable is a property of the form itself. It's set
// during the constructor. It's just a `TAdsTable` instance.
// The index info is set in that constructor as well (tag,
// expression, type, etc.).
AdsTable.AdsRegisterCallbackFunction(@ProgressCallBack, 1);
try
CreateIndexes;
finally
// Unhook the progress callback
AdsTable.AdsClearCallbackFunction;
// Clear the outside reference to the progress bar
PB := nil;
end;
end;
请注意,回调必须是独立的过程(如上所示),而不是表单方法。我已经展示了一种方法,通过使用对进度条的单元全局引用,不必对特定表单名称的访问进行硬编码。
于 2012-08-02T02:32:41.987 回答