About SQLWait cursor problems

About SQLWait cursor problems of the Delphi 2.0 and Delphi 3.0
--------------------------------------------------------------

Delphi 2.0  VLC source code has a problem.

At unit DB.PAS we can read...
---------
function TSession.ServerCallBack(CBInfo: Pointer): CBRType;
const
  MinWait = 500;
begin
  Result := cbrUSEDEF;
  if (FCBSCType = cbscSQL) and (GetCurrentThreadID = MainThreadID) then
  begin
    if StartTime = 0 then
    begin
      TimerID := SetTimer(0, 0, 1000, @TimerCallBack);
      AcquiredTimer := TimerID <> 0;
      StartTime := GetTickCount;
    end
    else if AcquiredTimer and (GetTickCount - StartTime > MinWait) then
      Screen.Cursor := crSQLWait;
  end;
end;
---------
and..
---------
procedure FreeTimer;
begin
  if AcquiredTimer then
  begin
    KillTimer(0, TimerID);
    AcquiredTimer := False;
    StartTime := 0;
    Screen.Cursor := crDefault;
  end;
end;

{ Timer callback function }

procedure TimerCallBack(hWnd: HWND; Message: Word; TimerID: Word;
  SysTime: LongInt); stdcall;
begin
  FreeTimer;
end;
--------

So after 500 milliseconds Screen.Cursor becomes crSQLWait and after
a second FreeTimer restores it to crDefault. As a result at SQL request
time we see cursor blinking (crSQLWait <-> crDefault).

No problem until ShowModal procedure (Forms unit) or
ReadFileNames procedure (FileCtrl unit) were used. These procedures
save Screen.Cursor (crSQLWait), perform its job (at this time FreeTimer
procedure makes Screen.Cursor := crDefault) and then
restore the cursor saved (crSQLWait). As a result Screen.Cursor becomes
crSQLWait "forever".

At Delphi 3.0 source we can found the attempt to correct this error.
But only at ShowModal procedure. So ReadFileNames (and any user code
which saves and restores Screen.Cursor) still may cause the same problem.

I made one correction and I like it
-----------------------------------
procedure FreeTimer;
begin
  // if AcquiredTimer then // Old code
  if AcquiredTimer and (Screen.Cursor = crSQLWait) then // New code
  begin
    KillTimer(0, TimerID);
    AcquiredTimer := False;
    StartTime := 0;
    Screen.Cursor := crDefault;
  end;
end;
------------------------------------

Sorry for my English! :-(

Good luck!
--
Igor Mikhalev, SSC "Octant" Ltd, Odessa, Ukraine
------------------------------------------------
(380482) 25-23-28     m...@octant.tenet.odessa.ua