在 Delphi 中获取 Advantage Database 查询的进度

Posted

技术标签:

【中文标题】在 Delphi 中获取 Advantage Database 查询的进度【英文标题】:Get the progress of an Advantage Database query in Delphi 【发布时间】:2012-08-02 02:21:08 【问题描述】:

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

【问题讨论】:

【参考方案1】:

您需要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:devzone.advantagedatabase.com/dz/WebHelp/Advantage11/…Callback Functionality/Caveatsdevzone.advantagedatabase.com/dz/WebHelp/Advantage11/…在帮助中有详细说明,但也需要注意的是,如果注册的函数(ProgressCallback)返回非零值,它将发出中止操作的信号。

以上是关于在 Delphi 中获取 Advantage Database 查询的进度的主要内容,如果未能解决你的问题,请参考以下文章

Advantage .NET 数据提供程序 - AdsConnection - 数据源

如何在 ASP.net MVC3 中获取 Advantage Database 数据?

如何使用 Advantage PHP Extension 获取行数?

Delphi Can't load package 找不到指定的模块

为 Advantage 数据库服务器 10 创建 ERD

Advantage Database ERD,来自现有数据库。