Hi Folks!
After the first use of grKeyRead from the pascal interface of GRX, the ordinary "readln" doesn't work anymore. As it seems, the input is consumed before it reaches the screen.
Does anyone have an idea how to fix this?
Thanks
Markus
Markus Gerwinski a écrit :
Hi Folks!
After the first use of grKeyRead from the pascal interface of GRX, the ordinary "readln" doesn't work anymore. As it seems, the input is consumed before it reaches the screen.
Does anyone have an idea how to fix this?
You may use the TFDD mechanism in Pascal. I have never used it for reading, only for writing through ordinary pascal write() while in graphics mode.
Briefly speaking I defined a function:
function WriteGrafChars(var PrivateData; const Buffer; Size : SizeType) : SizeType;
(look to the unit gpc.pas for the correct prototype) which output the chars through the graphics function OutText() (it was the BGI interface))
and a structure to save default output interface
type RecTFDD = record OpenProc : TOpenProc; SelectFunc : TSelectFunc; SelectProc : TSelectProc; ReadFunc : TReadFunc; WriteFunc : TWriteFunc; FlushProc : TFlushProc; CloseProc : TCloseProc; DoneProc : TDoneProc; PrivateData : Pointer end;
var GrafWriteActif : boolean; { flag a usage interne} OldOutput : RecTFDD; { Stores output I/O channel }
and then switched it on when entering graphics mode by calling:
procedure SetGrafWriteON; { Redirects standard output to the WriteGrafChars function. } begin if GrafWriteActif then Erreur('tentative de SetGrafWriteOn alors qu''il l''etait deja'); with OldOutput do begin GetTFDD(Output,OpenProc,SelectFunc,SelectProc,ReadFunc, WriteFunc,FlushProc,CloseProc,DoneProc, PrivateData); SetTFDD(Output,OpenProc,SelectFunc,SelectProc,ReadFunc, WriteGrafChars,FlushProc,CloseProc,DoneProc, PrivateData); end; GrafWriteActif:=true; end; { SetGrafWriteON }
and switched it off when back to text mode by calling:
procedure SetGrafWriteOFF; { Restores original output I/O channel } begin if not GrafWriteActif then Erreur('tentative de SetGrafWriteOff alors qu''il l''etait deja'); with OldOutput do SetTFDD(Output,OpenProc,SelectFunc,SelectProc,ReadFunc, WriteFunc,FlushProc,CloseProc,DoneProc, PrivateData); GrafWriteActif:=false; end; { SetGrafWriteOFF }
It works fine
Maurice
Hi!
Markus Gerwinski wrote:
After the first use of grKeyRead from the pascal interface of GRX, the ordinary "readln" doesn't work anymore. As it seems, the input is consumed before it reaches the screen.
GRX catches all keyboard (and mouse) input. Instead of file oriented I/O like Read, ReadLn (or scanf for that matter), use GrMouseGetEvent and friends.
You can also use GrMouseGetEvent and friends to define your own Read/ReadLn through a TFDD, as Maurice already pointed out.
Hope this helps,
Peter