3
我已经搜索和搜索,但无法找到如何在Delphi中获取查询的进度。我找到了有关Advantage .NET数据提供者的一些信息,但可以在Delphi中使用一些帮助。在Delphi中获取Advantage数据库查询的进度
我已经搜索和搜索,但无法找到如何在Delphi中获取查询的进度。我找到了有关Advantage .NET数据提供者的一些信息,但可以在Delphi中使用一些帮助。在Delphi中获取Advantage数据库查询的进度
你想要AdsRegisterCallbackFunction方法。下面是一个用于在创建TAdsTable索引期间显示进度的简单示例;它的工作原理完全一样的方式进步的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;
注意回调必须是一个独立的程序(如上图所示),而不是形式的方法。我已经展示了一种不必通过使用进度条的单位全局引用来硬编码访问特定表单名称的方法。
我将包含帮助文件链接作为额外的FYI。 AdsRegisterCallback:http://devzone.advantagedatabase.com/dz/WebHelp/Advantage11/index.html?ade_adsregistercallbackfunction.htm 回调功能/注意事项 http://devzone.advantagedatabase.com/dz/WebHelp/Advantage11/index。 html?master_callback_functionality.htm 在帮助中有详细说明,但也值得注意的是,如果注册函数(ProgressCallback)返回一个非零值,它将发出信号以中止操作。 – Edgar 2012-08-02 14:02:05
这很棒。非常感谢你们! – 2012-08-02 19:58:46