2012-08-02 4 views

답변

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; 

참고하지 양식 방법. 진행률 표시 줄에 대한 단위 글로벌 참조를 사용하여 특정 양식 이름에 대한 액세스를 하드 코딩 할 필요가없는 방법을 보여 줬습니다.

+2

추가 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)가 0이 아닌 값을 반환하면 작업을 중단하라는 신호를 보냅니다. – Edgar

+0

이것은 우수합니다. 둘 다 대단히 감사합니다! –

관련 문제