gpt4 book ai didi

delphi - 在 Delphi 中获取 Advantage 数据库查询的进度

转载 作者:行者123 更新时间:2023-12-03 15:46:44 32 4
gpt4 key购买 nike

我找了又找,但没有找到如何在Delphi中获取查询的进度。我找到了有关 Advantage .NET 数据提供程序的一些信息,但可以使用 Delphi 的一些帮助。

最佳答案

您想要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;

请注意,回调必须是独立过程(如上所示),而不是表单方法。我展示了一种方法,通过使用进度条的单元全局引用,不必硬编码对特定表单名称的访问。

关于delphi - 在 Delphi 中获取 Advantage 数据库查询的进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11770203/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com