[fpc-pascal]Bug in Win32 CRT unit: Type-ahead doesn't work.

Rich Pasco pasco at acm.org
Fri Nov 10 22:43:26 CET 2000


Porting some utilities from Borland Pascal 7.01 (DOS target) to Free
Pascal 1.0.2 (WIN32 target), I found that the CRT unit in Free Pascal
does not properly handle type-ahead.  Characters the user types before
the program is ready to read them are sometimes lost.

Below is a simple program which illustrates the problem.  When it
is compiled under Borland Pascal, all characters the user types are
displayed after the Delay().  When compiled under Free Pascal, keys
pressed while the Delay() statement is executing are lost (not picked
up by the ReadKey).

uses
  CRT;
var
  k: char;
begin
  WriteLn('Type a few words.  Hit Enter to quit:');
  repeat
    delay(400);
    k := ReadKey;
    if k=#0 then Readkey (* discard second half of function keys *)
    else write(K) (* but echo ASCII to screen *)
  until k=#$0D;   (* terminate with ENTER key *)
end.

Please note that the fault is not with Delay().  I discovered the
problem in a large application where there were intensive computations
happening.  The Delay() is just to make the test program simple.

Please also note that I am not referring to the overflow that happens
when the keystroke buffer is full (and there is a "beep" sound for
each lost keystroke).  This problem happens when there are just a few
characters in the buffer.

My compiler options (set by my pp386.cfg) are:
 -Ch8000000 -Sgico -Xs -l -viwnh
 -Fud:\pp/units/$TARGET
 -Fud:\pp/units/$TARGET/*
 -Fud:\pp/units/$TARGET/rtl

I would be interested in any comments on this matter.

     - Rich







More information about the fpc-pascal mailing list