検索して検索しましたが、Delphi でクエリの進行状況を取得する方法がわかりません。Advantage .NET データ プロバイダーに関する情報をいくつか見つけましたが、Delphi に関するヘルプが必要です。
1 に答える
7
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;
コールバックは、フォーム メソッドではなく、(上記のように) スタンドアロン プロシージャである必要があることに注意してください。プログレス バーへの unit グローバル参照を使用して、特定のフォーム名へのアクセスをハードコーディングする必要がない方法を示しました。
于 2012-08-02T02:32:41.987 に答える