Search code examples
delphiturbopower

ASyncPro 5.00 in Delphi 2010 - Range Check Error


Trying to get AsyncPro running in D2010. Using the 5.00 version from Source Forge.

The AsyncPro code (in OOMisc.pas) below is failing with a range check errror on the MakeLong line below. I don't have a clue how to start debugging this.

Does anyone have ASyncPro running in D2010, or have some insight into what might be going on below? A posting by me on the SourceForge yielded no responses.

function SafeYield : LongInt;
  {-Allow other processes a chance to run}
var
  Msg : TMsg;
begin
  SafeYield := 0;
  if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then begin
    if Msg.Message = wm_Quit then
      {Re-post quit message so main message loop will terminate}
      PostQuitMessage(Msg.WParam)
    else begin
      TranslateMessage(Msg);
      DispatchMessage(Msg);
    end;
    {Return message so caller can act on message if necessary}
    SafeYield := MAKELONG(Msg.Message, Msg.hwnd);  // Range Check Error on this line!
  end;
end;

TIA


Solution

  • It seems that you compile the code with range checking on:

    {$R+}
    function Test(A, B: LongWord): LongInt;
    begin
      Result:= MakeLong(A,B);
    // Project .. raised exception class ERangeError with message 'Range check error'.
    end;
    

    You can switch range checking off to get rid off the runtime error, but the result of

    SafeYield := MAKELONG(Msg.Message, Msg.hwnd)
    

    is incorrect if one of the arguments (or both) is above 2^16 - 1.

    Looks like the code was ported from 16-bit AsyncPro version without change to 32-bit version and the bug existed where through all 32-bit AsyncPro versions.