Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-11

Bug in Win32 CRT unit: Type-ahead doesn't work.

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rich Pasco

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

Reply by email